[Numpy-discussion] How do I do this?
Keith Goodman
kwgoodman at gmail.com
Sat Aug 30 10:39:08 EDT 2008
On Sat, Aug 30, 2008 at 7:29 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Sat, Aug 30, 2008 at 6:24 AM, Alan G Isaac <aisaac at 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])
Why did I send that? Sorry. I saw Stéfan's (np.sign(a) | 1), plugged
it in and sent it. But Stéfan already did that.
An automated 5 minute delay on sending numpy email would cut the email
you get from me in half.
More information about the NumPy-Discussion
mailing list