I am trying to add column names to an existing numpy array.
I have seen in this question that .dtype.names provides (and sets) the column names of a numpy array.
However when I have an existing array and I try to name the columns I get the following message.
I am sure it is a basic question and I am missing something pretty basic, but still can not find the answer:
a = np.array([[1,2,3],[4,5,6]])
a.dtype.names = 'ColA', 'ColB', 'ColC'
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-247-793bf2e18e51> in <module>
1 a = np.array([[1,2,3],[4,5,6]])
----> 2 a.dtype.names = ('ColA', 'ColB', 'ColC')
ValueError: there are no fields defined
EDIT:
It appears that only structured arrays can have named columns in numpy (numpy, named columns) and that numpy arrays can not have named columns.
structuredarray. You can't 'add' column names to a existing array.