[Numpy-discussion] How do I do this?
Stéfan van der Walt
Sat Aug 30 01:46:28 CDT 2008
2008/8/29 Christopher Barker <Chris.Barker@noaa.gov>:
> How can I do this without another line of code special casing the 0,
> which isn't that big I deal, but it seems kind of ugly...
> >>> a[a==0] = min_value
> >>> np.sign(a) * np.maximum(np.abs(a), min_value)
> array([ 2, 2, 2, 3, 4, -5])
(np.sign(a) | 1) * np.maximum(np.abs(a), min_value)
is a little bit easier on the eye.
More information about the Numpy-discussion