[Numpy-discussion] How do I do this?

Christopher Barker Chris.Barker@noaa....
Fri Aug 29 17:13:36 CDT 2008

Alan G Isaac wrote:
> Does this do what you want?
> idx = np.abs(a)<min_value
> a[idx] = min_value

out of interest, is there any performance difference between:

a[np.abs(a)<min_value] = min_value


a = np.where(np.abs(a)<min_value, min_value, a)

I think the former is more readable.


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the Numpy-discussion mailing list