[Numpy-discussion] numarray.where confusion

Francesc Alted falted at pytables.org
Wed May 26 09:07:10 CDT 2004


A Dimecres 26 Maig 2004 17:41, Todd Miller va escriure:
> Here's how I did it (there was an easier way I overlooked):
> 
> a = arange(10)
> m1 = where(a > 5, 1, 0).astype('Bool')
> m2 = where(a < 8, 1, 0).astype('Bool')
> a[m1 & m2] = array([10, 20])

Perhaps the easier way looks like this?

>>> a = arange(10)
>>> a[(a>5) & (a<8)] = array([10, 20])
>>> a
array([ 0,  1,  2,  3,  4,  5, 10, 20,  8,  9])

Indexing is a very powerful (and fun) thing, indeed :)

-- 
Francesc Alted





More information about the Numpy-discussion mailing list