[Numpy-discussion] Setting small numbers to zero.
josef.pktd at gmail.com
josef.pktd at gmail.com
Wed Mar 17 11:57:05 EDT 2010
On Wed, Mar 17, 2010 at 11:56 AM, Keith Goodman <kwgoodman at gmail.com> wrote:
> On Wed, Mar 17, 2010 at 8:51 AM, gerardob <gberbeglia at 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.]])
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
But as Skipper said before
You might find these helpful.
http://www.scipy.org/Tentative_NumPy_Tutorial
http://www.scipy.org/Numpy_Example_List
Josef
More information about the NumPy-Discussion
mailing list