[Numpy-discussion] Setting small numbers to zero.
Keith Goodman
kwgoodman@gmail....
Wed Mar 17 10:56:05 CDT 2010
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]]
Here's one way:
>> a = np.array([[0.003,2],[23,0.0001]])
>> a[np.abs(a) < 0.01] = 0
>> a
array([[ 0., 2.],
[ 23., 0.]])
More information about the NumPy-Discussion
mailing list