[Numpy-discussion] How do I do this?
Christopher Barker
Chris.Barker@noaa....
Fri Aug 29 17:08:25 CDT 2008
Alan G Isaac wrote:
> Does this do what you want?
> idx = np.abs(a)<min_value
> a[idx] = min_value
yup, that's it. I had forgotten about that kind of indexing, even though
I used it for: a[a==0] = min_value
Keith Goodman wrote:
> If you only have integers then
>
>>> x
> array([ 1, 2, -5, -1, 0])
>>> np.sign(x+1e-16) * np.maximum(np.abs(x), 2)
> array([ 2., 2., -5., -2., 2.])
that would work, though I like Alan's better.
thanks,
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
More information about the Numpy-discussion
mailing list