Properties of fields in numpy
Hi, I don't specially like the 'void*' typecasting that are receiving the types in fields in situations like: In [143]:dtype = numpy.dtype([ .....: ('x', '<i4', (2,)), .....: ('Info',[ .....: ('name', '<U120'), .....: ('weight', '<f4')])]) In [147]:dtype.fields['x'][0].name Out[147]:'void64' were you can see that we have lost the information about the native type of the 'x' field. Rather, I'd expect something like: In [147]:dtype.fields['x'][0].name Out[147]:'int32' although for this to be complete one should add a 'shape' attribute to dtype: In [147]:dtype.fields['x'][0].shape Out[147]:(2,) In fact, this information is already contained in dtype container: In [148]:dtype.fields['x'][0] Out[148]:dtype(('<i4',(2,))) but this is clearly little consistent with the current mapping of the dtype.fields['x'] attributes. I strongly feel that this suggested approach makes more sense than the current one. Thoughts? --
0,0< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data "-"
Francesc Altet wrote:
Hi,
I don't specially like the 'void*' typecasting that are receiving the types in fields in situations like:
In [143]:dtype = numpy.dtype([ .....: ('x', '<i4', (2,)), .....: ('Info',[ .....: ('name', '<U120'), .....: ('weight', '<f4')])])
In [147]:dtype.fields['x'][0].name Out[147]:'void64'
were you can see that we have lost the information about the native type of the 'x' field. Rather, I'd expect something like:
Well, it's actually there. Look at dtype.fields['x'][0].subdtype[0] dtype.fields['x'][0].subdtype[1] The issue is that the base data-type of the 'x' field is void-64 (that's the dtype object the array "sees"). -Travis
Francesc Altet wrote:
Hi,
I don't specially like the 'void*' typecasting that are receiving the types in fields in situations like:
In [143]:dtype = numpy.dtype([ .....: ('x', '<i4', (2,)), .....: ('Info',[ .....: ('name', '<U120'), .....: ('weight', '<f4')])])
In [147]:dtype.fields['x'][0].name Out[147]:'void64'
were you can see that we have lost the information about the native type of the 'x' field. Rather, I'd expect something like:
In SVN of numpy, the dtype objects now have a .base attribute and a .shape attribute. The .shape attribute returns (1,) or the shape of the sub-array. The .base attribute returns the data-type object of the base-type, or a new reference to self, if the object has no base.type. Thus, in current SVN dtype['x'].base.name would always give you what you want. -Travis
A Dimarts 07 Febrer 2006 01:08, Travis Oliphant va escriure:
In SVN of numpy, the dtype objects now have a .base attribute and a .shape attribute.
The .shape attribute returns (1,) or the shape of the sub-array.
Uh, it wouldn't be better to put .shape = 1 in case of a scalar field and (...) for a non-scalar field? Remember that this is the current convention for the numpy protocol.
The .base attribute returns the data-type object of the base-type, or a new reference to self, if the object has no base.type.
Thus, in current SVN
dtype['x'].base.name would always give you what you want.
Great. I like it. Thanks! --
0,0< Francesc Altet http://www.carabos.com/ V V Cárabos Coop. V. Enjoy Data "-"
participants (2)
-
Francesc Altet
-
Travis Oliphant