From: Christopher B. <Chr...@no...> - 2006-05-02 00:06:37
|
Hi all, I was just trying to use the putmask() method to replace a bunch of values with the same value and got and error, where the putmask() function works fine: >>> import numpy as N >>> a = N.arange(5) >>> a array([0, 1, 2, 3, 4]) >>> a.putmask(a > 3, 3) Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: putmask: mask and data must be the same size >>> N.putmask(a, a > 3, 3) >>> a array([0, 1, 2, 3, 3]) and: >>> help (N.ndarray.putmask) putmask(...) a.putmask(values, mask) sets a.flat[n] = v[n] for each n where mask.flat[n] is TRUE. v can be scalar. indicates that it should work. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
From: Sasha <nd...@ma...> - 2006-05-02 02:06:20
|
Do we really need the putmask method? With fancy indexing the obvious way to do it is >>> a[a>3] =3D 3 and it works fine. Maybe we can drop putmask method before 1.0 instead of fixing the bug. On 5/1/06, Christopher Barker <Chr...@no...> wrote: > Hi all, > > I was just trying to use the putmask() method to replace a bunch of > values with the same value and got and error, where the putmask() > function works fine: > > >>> import numpy as N > >>> a =3D N.arange(5) > >>> a > array([0, 1, 2, 3, 4]) > >>> a.putmask(a > 3, 3) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ValueError: putmask: mask and data must be the same size > > >>> N.putmask(a, a > 3, 3) > >>> a > array([0, 1, 2, 3, 3]) > > and: > > >>> help (N.ndarray.putmask) > putmask(...) > a.putmask(values, mask) sets a.flat[n] =3D v[n] for each n where > mask.flat[n] is TRUE. v can be scalar. > > indicates that it should work. > > -Chris > > > -- > Christopher Barker, Ph.D. > Oceanographer > > NOAA/OR&R/HAZMAT (206) 526-6959 voice > 7600 Sand Point Way NE (206) 526-6329 fax > Seattle, WA 98115 (206) 526-6317 main reception > > Chr...@no... > > > ------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job ea= sier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > |
From: John H. <jdh...@ac...> - 2006-05-02 03:42:33
|
>>>>> "Sasha" == Sasha <nd...@ma...> writes: Sasha> Do we really need the putmask method? With fancy indexing Sasha> the obvious way to do it is >>>> a[a>3] = 3 Sasha> and it works fine. Maybe we can drop putmask method before Sasha> 1.0 instead of fixing the bug. I'm +1 for backwards compatibility with the Numeric API where the cost of a fix isn't too painful. The way to speed numpy adoption is to make old Numeric code "just work" where possible with the new API. Bear in mind that many people may not even begin the port attempt until well after numpy 1.0. JDH |
From: Keith G. <kwg...@gm...> - 2006-05-02 15:34:11
|
On 5/1/06, Sasha <nd...@ma...> wrote: > Do we really need the putmask method? With fancy indexing the obvious > way to do it is > > >>> a[a>3] =3D 3 That would be a great example for the NumPy for Matlab Users page. http://www.scipy.org/NumPy_for_Matlab_Users |
From: Christopher B. <Chr...@no...> - 2006-05-02 17:01:53
|
John Hunter wrote: > Sasha> Do we really need the putmask method? With fancy indexing > Sasha> the obvious way to do it is > > >>>> a[a>3] = 3 Duh! I totally forgot about that, despite the fact that that was the one thing I missed when moving form Matlab to Numeric a few years back. > I'm +1 for backwards compatibility with the Numeric API where the cost > of a fix isn't too painful. I agree, however, does Numeric have a putmask() method? or only a putmask function? The numpy putmask function works fine. Still, this looks like a bug that may well apply to other methods, so it's probably worth fixing. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |