17 Mar
2010
17 Mar
'10
3:55 p.m.
On Wed, Mar 17, 2010 at 8:51 AM, gerardob <gberbeglia@gmail.com> wrote:
How can i modified all the values of a numpy array whose value is smaller than a given epsilon to zero?
Example epsilon=0.01 a = [[0.003,2][23,0.0001]]
output: [[0,2][23,0]]
Give this a try:
import numpy as np epsilon=0.01 a=np.array([[0.003,2],[23,0.0001]]) a array([[ 3.00000000e-03, 2.00000000e+00], [ 2.30000000e+01, 1.00000000e-04]]) a[np.abs(a) < epsilon] = 0 a array([[ 0., 2.], [ 23., 0.]])