[Numpy-discussion] How do I do this?
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
> 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.
Christopher Barker, Ph.D.
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
More information about the Numpy-discussion