I have an array Sum
with some elements being very small. I want to print this array based on a tolerance value tol
such that if any element is less than this, it becomes zero.
import numpy as np
tol = 1e-12
Sum = np.array([ 7.37551766e-08, -4.99999992e-17, 0.00000000e+00, 5.00000028e-16,
-4.99999984e-17, 0.00000000e+00, -4.83360759e-07])
for i in range(0,len(Sum)):
if (abs(Sum[i]) < tol):
Sum[i]==0
print(Sum)
The expected output is
array([ 7.37551766e-08, 0, 0.00000000e+00, 0,
0, 0.00000000e+00, -4.83360759e-07])