0

In the following code I want to print J values upto %.2f. How can I do that?

T= np.arange(1,4,1)
J= 1.0/T
print(J)  #[1.  0.5   0.333333  0.25]
print("%.2f" % J)
Armali
  • 18,255
  • 14
  • 57
  • 171
huda
  • 37
  • 7
  • 2
    Possible duplicate of [How to pretty-printing a numpy.array without scientific notation and with given precision?](https://stackoverflow.com/questions/2891790/how-to-pretty-printing-a-numpy-array-without-scientific-notation-and-with-given) – Tom de Geus Jul 17 '18 at 11:24

1 Answers1

1

You could do it like that:

T= np.arange(1,4,1)
J= 1.0/T
print(("{:.2f}, "*len(J)).format(*J))
pascscha
  • 1,623
  • 10
  • 16