[Numpy-discussion] How do I do this?
Fri Aug 29 17:16:00 CDT 2008
On Fri, Aug 29, 2008 at 3:08 PM, Christopher Barker
> 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.
I thought -1 should go to -2. If not, then my attempt doesn't work.
More information about the Numpy-discussion