[Numpy-discussion] int32 twice in sctypes?
Travis Oliphant
oliphant at ee.byu.edu
Tue Nov 28 17:59:10 CST 2006
Matthew Brett wrote:
>Hi,
>
>I was a bit confused by this on 32 bit linux:
>
>In [30]:sctypes['int']
>Out[30]:
>[<type 'numpy.int8'>,
> <type 'numpy.int16'>,
> <type 'numpy.int32'>,
> <type 'numpy.int64'>,
> <type 'numpy.int32'>]
>
>Is it easy to explain the two entries for int32 here? I notice there
>is only one int32 entry for the same test on my 64 bit system.
>
>
>
The mapping from c-types to bit-width types is not one-to-one. All of
the c-types have their own array-scalar. Some of these have the same
bit-width and thus are named similarly.
numpy.int32 refers to exactly one of these c-types, but on some systems
(e.g. 32-bit), there will be another array scalar that also shows up
with the name numpy.int32
The easiest way to see them all is to observe
id(dtype('byte').type)
id(dtype('short').type)
id(dtype('intc').type)
id(dtype('int').type)
id(dtype('longlong').type)
But then compare:
dtype('byte').type
dtype('short').type
dtype('intc').type
dtype('int').type
dtype('longlong').type
dtype('intp').type will be one of the above as can be verified by
looking at
id(dtype('intp').type)
The sctypes['int'] list is a list of all the c-type ints. Thus, you
could generate the id's of the first 5 typeobjects using:
[id(x) for x in sctypes['int']]
-Travis
More information about the Numpy-discussion
mailing list