[SciPy-dev] Fancy indexing curiosity

Travis Oliphant oliphant.travis at ieee.org
Sun Jan 8 01:14:46 CST 2006


Travis Oliphant wrote:

>Sasha wrote:
>
>  
>
>>>>>x = array([1])
>>>>>m = array([1], bool)
>>>>>x[m] = ''
>>>>>x
>>>>>       
>>>>>
>>>>>          
>>>>>
>>array([12998744])
>> 
>>
>>    
>>
>>>>>x[m] = ''
>>>>>x
>>>>>       
>>>>>
>>>>>          
>>>>>
>>array([12998752])
>>
>>It looks like x gets the address of the '' object (note the number change).
>>This "feature" is present in 0.9.2 release and in svn 0.9.3.1831
>> 
>>
>>    
>>
>
>Thanks for this corner case.  Actually, it's getting whatever is in the 
>memory allocated.
>
>Try
>
>b = array('',x.dtype)
>
>b should be a size-0 array,  (there is actually 1 elementsize of memory 
>allocated for it though).
>
>The mapping code is iterating over b and resetting b whenever it runs 
>out of elements of b (every time in this case), except the data pointed 
>to by the iterator is never valid so this should not be allowed....
>
>I suppose instead, creating an iterator from a size-0 array could raise 
>an error.  This would be a great and simple place to catch this in the 
>code as well.
>
>  
>
This now raises an error....

-Travis




More information about the Scipy-dev mailing list