[Numpy-discussion] integer array creation oddity

Suchindra Sandhu suchindra@gmail....
Wed Jul 23 09:48:55 CDT 2008


Thanks Everyone.

On Mon, Jul 21, 2008 at 6:25 PM, Charles R Harris <charlesr.harris@gmail.com>
wrote:

>
>
> On Mon, Jul 21, 2008 at 3:37 PM, Stéfan van der Walt <stefan@sun.ac.za>
> wrote:
>
>> 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).
>>
>
> They correspond to two C types of the same size, int and long. On 64 bit
> systems you should have two int64 types, long and longlong.
>
> In [1]: dtype('i').name
> Out[1]: 'int32'
>
> In [2]: dtype('l').name
> Out[2]: 'int32'
>
> Chuck
>
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080723/bff548fd/attachment-0001.html 


More information about the Numpy-discussion mailing list