[Numpy-discussion] please comment on scalar types
haase at msg.ucsf.edu
Mon Aug 14 21:40:49 CDT 2006
Travis Oliphant wrote:
> Sebastian Haase wrote:
>> I have a record array with a field 'mode'
>> Mode is a small integer that I use to choose a "PixelType"
>> So I did:
>>>>> print PixelTypes[ mode ]
>> TypeError: tuple indices must be integers
>> -> return PixelTypes[ mode ]
>> (Pdb) p mode
>> (Pdb) p type(mode)
>> <type 'int32scalar'>
>> (Pdb) p isinstance(mode, int)
>> Since numpy introduced special scalar types a simple statement like this
>> doesn't work anymore ! Would it work if int32scalar was derived from int ? I
>> actually thought it was ...
> It does sub-class from int unless you are on a system where a c-long is
> 64-bit then int64scalar inherits from int.
> On my 32-bit system:
> isinstance(array([1,2,3]),int) is true.
I see -
yes I forgot - that test was indeed run on 64bit Linux.
And that automatically implies that there a 32bit-int cannot be used in
place of a "normal python integer" !?
I could see wanting to use int16 or event uint8 as a tuple index.
Logically a small type would be save to use in place of a bigger one ...
More information about the Numpy-discussion