Alan G Isaac wrote:
>>>> Alan G Isaac wrote:
>>>>> Does this do what you want? 
>>>>> idx = np.abs(a)<min_value 
>>>>> a[idx] = min_value 
> 
> Christopher Barker wrote:
>> -1 should go to -2
> 
> ok then:
> a[idx] = min_value*np.sign(a[idx])
> I think that's what you are saying?

nope:

 >>> a = np.array((0, 1, -1, 2, 3, -5,))
 >>> idx = np.abs(a)<min_value
 >>> a = np.array((0, 1, -1, 2, 3, -5,))
 >>> a
array([ 0,  1, -1,  2,  3, -5])

0 should go to 2 --it's not, because sign(0) == 0, so the 2 gets turned 
to zero, my original problem.

Frankly, as I've only seen sign() used for this sort of thing, it makes 
me think that sign(0) really should be 1 -- the identity -- I know that 
0 is neither positive nor negative, but as it is often used in this way, 
it would be more useful for sign(0) to be the identity.

I'm not advocating a change in numpy, I'm sure this is established 
standard, but it does seem I need to special case zero. (Or fudge it by 
adding an epsilon, as Keith suggested.

thanks all,
-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to