[Numpy-discussion] integer array creation oddity
Stéfan van der Walt
stefan@sun.ac...
Mon Jul 21 16:37:42 CDT 2008
2008/7/21 Suchindra Sandhu <suchindra@gmail.com>:
> Is that the recommended way of checking the type of the array? Ususally for
> type checkin, I use the isinstance built-in in python, but I see that will
> not work in this case. I must admit that I am a little confused by this. Why
> is type different from dtype?
Data-types contain additional information needed to lay out numerical
types in memory, such as byte-order and bit-width. Each data-type has
an associated Python type, which tells you the type of scalars in an
array of that dtype. For example, here are two NumPy data-types that
are not equal:
In [6]: d1 = np.dtype(int).newbyteorder('>')
In [7]: d2 = np.dtype(int).newbyteorder('<')
In [8]: d1.type
Out[8]: <type 'numpy.int32'>
In [9]: d2.type
Out[9]: <type 'numpy.int32'>
In [10]: d1 == d2
Out[10]: False
I don't know why there is more than one int32 type (I would guess it
has something to do with the way types are detected upon build; maybe
Robert or Travis could tell you more).
Regards
Stéfan
More information about the Numpy-discussion
mailing list