2

I'm trying to get rid of this format to make this file readable in another software.

import numpy as np

test=[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]
np.round(test,6)
print(test)

test2=[[5.1056e+02, 6.89752e+05, 4.5987126464655e+03],[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]]
test2=np.array(test2)
np.round(test2,6)
print(test2)

1st print gives me :

[510.56, 689752.0, 4598.7126464655]

2nd print gives me :

[[  5.10560000e+02   6.89752000e+05   4.59871265e+03]
 [  5.10560000e+02   6.89752000e+05   4.59871265e+03]]

Now the first result would be fine by me, but my data looks like test2. But I still don't understand what the second argument of np.round does, as it is supposed to limit the number of decimals, but I still get 4598.7126464655. But at least I'd get a usable format.

How can I make this work on something like test2 ? I tried this :

for i in range(np.shape(test2)[0]):
    np.round(test2[i])

print(test2)

Still gives me :

[[  5.10560000e+02   6.89752000e+05   4.59871265e+03]
 [  5.10560000e+02   6.89752000e+05   4.59871265e+03]]
Nils Werner
  • 34,832
  • 7
  • 76
  • 98
Pauline1006
  • 127
  • 1
  • 9
  • `np.round(test,6)` does not modify the `test` object itself. It returns a new object. So you have to do `test = np.round(test, 6)` – eumiro Feb 11 '15 at 09:26

1 Answers1

-1

4.59871265e+03 is actually equivalent to 4598.71265

>>> 4.59871265e+03 == 4598.71265
True

so your rounding works just fine. You need to set

np.set_printoptions(suppress=True)

before printing.

Nils Werner
  • 34,832
  • 7
  • 76
  • 98