[Numpy-discussion] numarray.where confusion

Todd Miller jmiller at stsci.edu
Wed May 26 09:29:06 CDT 2004


On Wed, 2004-05-26 at 12:06, Francesc Alted wrote:
> 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])

Much, much better.  Thanks!

Todd

> >>> a
> array([ 0,  1,  2,  3,  4,  5, 10, 20,  8,  9])
> 
> Indexing is a very powerful (and fun) thing, indeed :)
-- 
Todd Miller <jmiller at stsci.edu>





More information about the Numpy-discussion mailing list