[Numpy-discussion] bug !? dtype type_descriptor does not accept zero length tuple

Sebastian Haase haase at msg.ucsf.edu
Wed Aug 9 23:35:30 CDT 2006


Travis Oliphant wrote:
> Sebastian Haase wrote:
>> On Wednesday 09 August 2006 15:45, you wrote:
>>  
>>> Sebastian Haase wrote:
>>>    
>>>> On Wednesday 09 August 2006 15:18, Travis Oliphant wrote:
>>>>      
>>>>> If numarray supported it, then we should get NumPy to support it as 
>>>>> well
>>>>> unless there is a compelling reason not to.  I can't think of any 
>>>>> except
>>>>> that it might be hard to make it work.  What is '0i4' supposed to mean
>>>>> exactly?  Do you get a zero-sized field or is the field not included?
>>>>> I think the former will be much easier than the latter.   Would 
>>>>> that be
>>>>> O.K.?
>>>>>         
>>>> That's exactly what numarray did. The rest of my code is assuming that
>>>> all fields exist (even if they are empty). Otherwise I get a name 
>>>> error which is worse than getting an empty array.
>>>>       
>>> Do you have a simple code snippet that I could use as a test?
>>>
>>> -Travis
>>>     
>>
>> I think this should do it:
>>
>> a = N.arange(10, dtype=N.float32)
>> a.shape = 5,2
>> type_descr = [("int",   "<0i4"),("float", "<2f4")]
>> a.dtype = type_descr
>>
>>   
> 
> I'm not sure what a.shape = (5,2) is supposed to do.  I left it in the 
> unit-test out because assigning to the data-type you just defined 
> already results in
> 
> a['float'].shape being (5,2)
> 
> If it is left in, then an extra dimension is pushed in and
> 
> a['float'].shape is (5,1,2)
> 
> 
> This is due to the default behavior of assigning data-types when the new 
> data-type has a larger but compatibile itemsize then the old itemsize.

I have to admit that I don't understand that statement. I thought - just 
"visually" - that a.shape = 5,2 would make a "table" with 2 columns. 
Then I could go on and give those columns names...
Or is the problem that the type "2f4" refers to (some sort of) a "single 
column" with 2 floats grouped together !?

Thanks for implementing it so quickly,
Sebastian Haase





More information about the Numpy-discussion mailing list