问题
How do I convert an array like:
array([ -9.8737e+13, -9.8737e+13, -1.1265e+14, 1.5743e-01,
1.1265e+14, 9.8737e+13, 9.8737e+13])
into a readable form in numpy
or python
?
Thanks!
Chris
回答1:
Your array contains both large and small values. It's hard to present both in a readable way. If you use scientific notation the numbers can be shown in a compact form, but it's hard to tell at a glance which numbers are large and which are small.
Alternatively, you could display the floats without scientific notation, for example, like this:
In [132]: np.set_printoptions(formatter={'float_kind':'{:25f}'.format})
In [133]: x
Out[133]:
array([ -98737000000000.000000, -98737000000000.000000,
-112650000000000.000000, 0.157430,
112650000000000.000000, 98737000000000.000000,
98737000000000.000000])
which makes it easy to distinguish the large from the small, but now the eyes boggle looking at too many zeros.
After a while, you may want to go back to NumPy's default format, which you can do by calling np.set_printoptions()
without arguments.
In [134]: np.set_printoptions()
In [135]: x
Out[135]:
array([ -9.8737e+13, -9.8737e+13, -1.1265e+14, 1.5743e-01,
1.1265e+14, 9.8737e+13, 9.8737e+13])
Whatever the case, the above shows you how you can configure NumPy to display floats (or other types) any way you wish. See the docs for more on all the available options.
来源:https://stackoverflow.com/questions/21897637/making-scientific-notation-readable-from-a-numpy-array