[Numpy-discussion] dtype names and titles
N. Volbers
mithrandir42 at web.de
Sat Feb 11 04:46:02 EST 2006
I continue to learn all about the heterogeneous arrays...
When I was reading through the records.py code I discovered that besides
the 'names' and 'formats' for the fields of a numpy array you can also
specify 'titles'. Playing around with this feature I discovered a bug:
>>> import numpy
>>> mydata = [(1,1), (2,4), (3,9)]
>>> mytype = {'names': ['col1','col2'], 'formats':['i2','f4'],
'titles': ['col2', 'col1']}
>>> b = numpy.array( mydata, dtype=mytype)
>>> print b
[(1.0, 1.0) (4.0, 4.0) (9.0, 9.0)]
This seems to be caused by the fact that you can access a field by both
the name and the field title. Why would you want to have two names anyway?
By the way, is there an easy way to access a field vector by its index?
Right now I retrieve the field name from dtype.fields[-1][index] and
then return the 'column' by using myarray[name].
Best regards,
Niklas.
More information about the NumPy-Discussion
mailing list