[Numpy-discussion] How do I do this?
Keith Goodman
kwgoodman@gmail....
Sat Aug 30 09:29:09 CDT 2008
On Sat, Aug 30, 2008 at 6:24 AM, Alan G Isaac <aisaac@american.edu> wrote:
> Stéfan van der Walt wrote:
>> (np.sign(a) | 1) ...
>
> Ah, that's nice. How about
> idx = np.abs(a)<min_value
> a[idx] = min_value*(np.sign(a[idx]) | 1)
Or, since he asked to do it in one line,
>> min_value = 2
>> x
array([ 1, 2, -5, -1, 0])
>> np.sign(x | 1) * np.maximum(np.abs(x), min_value)
array([ 2, 2, -5, -2, 2])
More information about the Numpy-discussion
mailing list