I've a matrix with this shape:
>>> A = [ [12.11432, 10.00211, 9.44100],[0.12361, 5511.13478, 189.79823] ]
A is sparse matrix, I used exactly lil_matrix
. I want to divide each element of A by the sum of the all elements. The result of this division must be a matrix B with the same precision as A.
>>> from scipy.sparse import lil_matrix
>>> import numpy as np
>>> A = np.array([ [12.11432, 10.00211, 9.44100],[0.12361, 5511.13478, 189.79823] ])
>>> A = lil_matrix(A)
>>> B = A / A.sum()
>>> B.toarray()
array([[ 2.11322791e-03, 1.74477296e-03, 1.64689266e-03],
[ 2.15625889e-05, 9.61365048e-01, 3.31084961e-02]])
As you can see, the precision between A and B isn't the same.
So, How can I keep only 5 digit after the decimal point in the B matrix?