[Numpy-discussion] dtype attribute missing in numarray

Todd Miller jmiller at stsci.edu
Thu Jan 5 11:32:14 CST 2006


Sebastian Haase wrote:

>On Thursday 05 January 2006 10:25, you wrote:
>  
>
>>Sebastian Haase wrote:
>>    
>>
>>>Thanks Todd,
>>>I like this a lot.  Maybe it could be mentioned in the documention - I
>>>don't have any good suggestions on where, I just noticed that 'dtype' is
>>>not in the index.
>>>I assume the following assignment to 'dtype' is not that important !?
>>>
>>>      
>>>
>>>>>>na.__version__
>>>>>>            
>>>>>>
>>>'1.5.1'
>>>
>>>      
>>>
>>>>>>a = na.arange(10,dtype=na.float32)
>>>>>>a.dtype
>>>>>>            
>>>>>>
>>>Float32
>>>
>>>      
>>>
>>>>>>a.dtype = na.int32
>>>>>>            
>>>>>>
>>>Traceback (most recent call last):
>>> File "<input>", line 1, in ?
>>>AttributeError: can't set attribute
>>>      
>>>
>>Things are changing fast but I don't think this is supposed to work:
>>    
>>
>>>>>import scipy
>>>>>
>>>>>a = scipy.arange(10)
>>>>>
>>>>>a
>>>>>          
>>>>>
>>array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>
>>    
>>
>>>>>a.dtype
>>>>>          
>>>>>
>><type 'int32_arrtype'>
>>
>>    
>>
>>>>>a.dtype = scipy.int16
>>>>>          
>>>>>
>>Traceback (most recent call last):
>>
>>  File "<stdin>", line 1, in ?
>>
>>TypeError: attribute 'dtype' of 'scipy.bigndarray' objects is not writable
>>
>>My thinking was that you'd need a.astype() which returns a new array
>>object.  Since types vary in size,  it's not clear what it means to
>>assign type or how it would affect shape.
>>
>>    
>>
>No, only assignment with a type of same size was supposed to  work - that's 
>what I remember having read somewhere !.... BUT I think having that 
>restriction would be weird  to say the least ...
>
>Event thought being able to say 'a.dtype = <any type>'  just like one can say 
>'a.shape = <new shape>' would look nice  .  Then again <any shape> only 
>includes shapes that are "compatible" are accepted -> so that "compatible 
>types" _would_ really be the consequent restriction !?!?
>
>
>  
>
>>>Also: when / why was it decided that dtypes (float32, int32, ...) should
>>>be lowercase !? Aren't all python types usually uppercase ...
>>>      
>>>
>>The naming looks clean to me.    I don't know how the decision was made.
>>    
>>
>
>Is numarray going to change to this ( i.e.  a.dtype would return 'uint32'  and 
>'UInt32' would be the alias ) 
>  
>
I think we're close to the point where numarray/scipy compatibility 
breaks down / won't be built up.  numarray's .dtype is  returning a 
numarray type object, not a string.  Most notably,  the type object is 
not a numpy/scipy type object.   Also,  it has a different repr which 
spells the type in mixed case.

I returned numarray's type object because AFAIK newcore's .dtype returns 
a type object.   I also considered returning a string but that wouldn't 
really be compatible either.

Todd







More information about the Numpy-discussion mailing list