Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing values in a whole array

Tags:

python

numpy

I would like to ask how I can change the values in a whole NumPy array.

For example I want to change every value which is < 1e-15 to be equal to 1e-15.

like image 726
Purchawka Avatar asked Mar 27 '26 12:03

Purchawka


1 Answers

Assuming you mean a numpy array, and it's pointed to by a variable a:

np.fmax(a, 1e-15, a)

This finds the maximum of the two values given as the first two arguments (a and 1e-15) on a per-element basis, and writes the result back to the array given as the third argument, a.

I had a hard time finding the official docs for this function, but I found this.

like image 79
Lauritz V. Thaulow Avatar answered Mar 30 '26 01:03

Lauritz V. Thaulow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!