[Numpy-discussion] numpy putmask() method and a scalar.

Sasha ndarray at mac.com
Mon May 1 19:07:02 EDT 2006


Do we really need the putmask method?  With fancy indexing the obvious
way to do it is

>>> a[a>3] = 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 <Chris.Barker at noaa.gov> 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 = 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
>
> Chris.Barker at noaa.gov
>
>
> -------------------------------------------------------
> 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 easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>




More information about the NumPy-Discussion mailing list