# [Numpy-discussion] numarray.where confusion

Alok Singhal as8ca at virginia.edu
Wed May 26 11:04:13 CDT 2004

```On 26/05/04: 10:43, Andrew Straw wrote:
> Todd Miller wrote:
> >On Wed, 2004-05-26 at 12:06, Francesc Alted wrote:
> >
> >>>>>a = arange(10)
> >>>>>a[(a>5) & (a<8)] = array([10, 20])
> >>>>>
> Is there an equivalently slick way to accomplish to what I'm trying
> below?  (the the values in c[:,1] get changed based on the same-row
> values in c[:,0]?)
>
> from numarray import *
> a=arange(10)
> b=arange(10)+20
> c=concatenate((a[:,NewAxis],b[:,NewAxis]),axis=1)
> c[c[:,0]>7][:,1] = 0 # doesn't work because it makes a copy and
> therefore doesn't modify c

Well, for your case, the following works:

>>> print c
[[ 0 20]
[ 1 21]
[ 2 22]
[ 3 23]
[ 4 24]
[ 5 25]
[ 6 26]
[ 7 27]
[ 8 28]
[ 9 29]]
>>> t0 = c[:, 0]
>>> t1 = c[:, 1]
>>> t1[t0 > 7] = 0
>>> print c
[[ 0 20]
[ 1 21]
[ 2 22]
[ 3 23]
[ 4 24]
[ 5 25]
[ 6 26]
[ 7 27]
[ 8  0]
[ 9  0]]

Not sure this helps in your real code though.

Alok

--
Alok Singhal (as8ca at virginia.edu)          *   *
Graduate Student, dept. of Astronomy   *           *     *
University of Virginia
http://www.astro.virginia.edu/~as8ca/              *    *

```