Reputation: 59
When I compute an operation and it is displayed in the python terminal (spyder) the numbers has to many decimals and make difficult (sometimes) read the result, for example
T = array([[ 5, 5, 8, 8, 7],
[ 7, 8, 6, 9, 6],
[ 6, 7, 8, 9, 8],
[ 1, 7, 1, 7, 9],
[ 4, 2, 3, 6, 10]])
print( T @ inv(t) )
in the terminal I have
[[ 1.00000000e+00 4.44089210e-16 0.00000000e+00 -2.49800181e-16
3.33066907e-16]
[ 8.88178420e-16 1.00000000e+00 0.00000000e+00 5.55111512e-17
0.00000000e+00]
[ 0.00000000e+00 4.44089210e-16 1.00000000e+00 -8.32667268e-17
0.00000000e+00]
[ 1.77635684e-15 -4.44089210e-16 0.00000000e+00 1.00000000e+00
1.11022302e-16]
[-8.88178420e-16 -4.44089210e-16 3.55271368e-15 -2.22044605e-16
1.00000000e+00]]
and this is a simple Identity matrix. The question is
¿is it posible to reduce the number of decimals in the matrix to show me a more easy one? just like this
np.array([[1, 0, 0, 0, 0],
[0, 1, 0, 0, 0],
[0, 0, 1, 0, 0],
[0, 0, 0, 1, 0],
[0, 0, 0, 0, 1]])
or even better, not only just for the matrix but all numbers in the terminal
The option
'%.2f' % T @ inv(T)
give me the error
TypeError: only size-1 arrays can be converted to Python scalars
I'm talking about to change all displays in the terminal from a initial comand in the head of the script
Upvotes: 1
Views: 1046