[SciPy-dev] Fancy indexing curiosity
Travis Oliphant
oliphant.travis at ieee.org
Sun Jan 8 02:09:28 EST 2006
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.
A size-0 array has nothing to iterate over...
-Travis
More information about the SciPy-Dev
mailing list