user288609 user288609 - 1 year ago 55
Python Question

fast way to replace the small enough value with zero

I have created a multi-dimensional array, whose information is shown as follows.

It can be seen that there a lot of values that are quite small. In fact, they all should be equal to zero. Are there any quick ways, to replace those very small values (e.g., <=e-10) with 0. Thanks.

enter image description here

Answer Source

you can use the round method with the following parameters:

arr[j][i] = round(arr[j][i], 10) 

to round to 10 digits (e^-10)

numpy also has a method for this as well to round the whole array

numpy.around(a,10,a)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download