[Numpy-discussion] More about data types in NumPy

Travis Oliphant oliphant.travis at ieee.org
Wed Sep 27 12:35:51 EDT 2006


Francesc Altet wrote:
> Hello,
>
> Sorry for being insistent, but I recognize that I'm having a bad time
> with NumPy data type rational. Is there an explanation for this?:
>
>   
>>>> numpy.dtype('i4').type
>>>>         
> <type 'numpy.int32'>
>   
>>>> numpy.dtype('int32').type
>>>>         
> <type 'numpy.int32'>
>   
>>>> numpy.dtype('i4').type == numpy.dtype('int32').type
>>>>         
> True
>
> So far so good, but is the next the intended behaviour?
>
>   
>>>> numpy.typeDict['i4']
>>>>         
> <type 'numpy.int32'>
>   
>>>> numpy.typeDict['int32']
>>>>         
> <type 'numpy.int32'>
>   
>>>> numpy.typeDict['i4'] == numpy.typeDict['int32']
>>>>         
No, this isn't correct behavior.   This time you've caught an actual 
problem :-)

The typeDict (actually the sctypeDict --- scalar-type-dictionary returns 
a scalar type given a string not a data-type object) is only used if no 
other conversion can be found for the object.  It used to be much more 
useful before the data-type objects were formalized last year.

-Travis






More information about the NumPy-Discussion mailing list