[Numpy-discussion] numarray.where confusion
Andrew Straw
strawman at astraw.com
Wed May 26 10:44:05 CDT 2004
Todd Miller wrote:
>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])
>>>>>
>>>>>
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
Cheers!
Andrew
More information about the Numpy-discussion
mailing list