1

I have an array that looks like this:

[[  9.71369349e+02   1.06915603e+03   1.14821723e+03   3.16300000e+02]
 [  1.83700564e+03   1.85500390e+03   1.87149745e+03   7.69400000e+01]
 ...,
 [  1.00000000e+20   5.56290955e+02   7.92477067e+02   4.34600000e+01]]

How can I pretty print this so that the values are not exponentiated?

I've tried using:

sp.set_printoptions(suppress=True)

This had no effect.

turtle
  • 7,533
  • 18
  • 68
  • 97
  • What happened exactly? Because it works decently (see e.g. this post for example http://stackoverflow.com/questions/2891790/pretty-printing-of-numpy-array). – Aleksander Lidtke Aug 09 '13 at 11:25
  • The array prints with the same format (as in my example) regardless of `set_printoptions`. – turtle Aug 09 '13 at 11:32
  • I can confirm that `set_printoptions` is working as `sp.set_printoptions(precision=3)` formats correctly, albeit still showing the exponents (`9.713e+02`), which is not what I want. – turtle Aug 09 '13 at 11:33
  • Can you post the relevant part of your code where you set the options and print the array? Also, which version of python are you using? – Aleksander Lidtke Aug 09 '13 at 11:54

1 Answers1

3

To remove all exponentiation you need to call the formatter argument. Modifying the example in the docs, something like this should do the trick:

sp.set_printoptions(formatter={"float": lambda x: '{:.20f}'.format(x)})

This uses string formatting to print a fixed point number(that is the 'f') with 20 decimal places. So 9.71369349e+02 is represented as 971.36934900000005654874. You will need to decide exactly how to handle this number of decimal places.

Greg
  • 11,654
  • 3
  • 44
  • 50