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
  • 16,557
  • 13
  • 53
  • 152
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,424
  • 8
  • 16