I'm doing matrix factorization whose output matrix has non-integer entries. To make the display more compact, I would like to ask how to limit the number of decimals of results. Thank you so much!
import numpy as np
import scipy.linalg as la
A = np.array([[1, 0, 8, 7, 8, 1],
[0, 1, 2, 8, 9, 2],
[5, 1, 0, 6, 10, 3],
[5, 4, 4, 8, 10, 4]])
(P, L, U) = la.lu(A)
F = np.array(sorted(U, key=lambda x: tuple(x!=0), reverse=False))
print(F)
[[ 0. 0. 0. 6.85483871 8.51612903 1.62903226]
[ 0. 0. 8.26666667 5.93333333 6. 0.46666667]
[ 0. 3. 4. 2. 0. 1. ]
[ 5. 1. 0. 6. 10. 3. ]]
PS: I would like to ask for a global setting instead of repeating apply the function round
to each output.