[Numpy-discussion] numarray.where confusion
Alok Singhal
as8ca at virginia.edu
Wed May 26 07:49:40 CDT 2004
Hi,
I am having trouble understanding how exactly "where" works in
numarray.
What I am trying to do:
I am preparing a two-level mask in an array and then assign values to
the array where both masks are true:
>>> from numarray import *
>>> a = arange(10)
>>> # First mask
>>> m1 = where(a > 5)
>>> a[m1]
array([6, 7, 8, 9])
>>> # Second mask
>>> m2 = where(a[m1] < 8)
>>> a[m1][m2]
array([6, 7])
>>> # So far so good
>>> # Now change some values
>>> a[m1][m2] = array([10, 20])
>>> a[m1][m2]
array([6, 7])
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> # Didn't work
>>> # Let's try a temporary variable
>>> t = a[m1]
>>> t[m2]
array([6, 7])
>>> t[m2] = array([10, 20])
>>> t[m2], t
(array([10, 20]), array([10, 20, 8, 9]))
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
So, my assignment to a[m1][m2] seems to work (no messages), but it
doesn't produce the effect I want it to.
I have read the documentation but I couldn't find something that would
explain this behavior.
So my questions:
- did I miss something important in the documentation,
- I am expecting something I shouldn't, or
- there is a bug in numarray?
Thanks,
Alok
--
Alok Singhal (as8ca at virginia.edu) __
Graduate Student, dept. of Astronomy / _
University of Virginia \_O \
http://www.astro.virginia.edu/~as8ca/ __/
More information about the Numpy-discussion
mailing list