1

I am using a numpy array to hold data
the array is holding my date lke this

1.2251999e+03 1.2251999e+03 1.2251999e+02

when I would prefer it held is as a floating point

how can I force the array to hold data as I would prefer it where it holds 10. instead of 1.0+01?

thankyou

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Temp_file
  • 41
  • 6
  • Hi, this question seems to have been answered here: https://stackoverflow.com/questions/2891790/how-to-pretty-print-a-numpy-array-without-scientific-notation-and-with-given-pre – Pavan Yalamanchili May 08 '20 at 18:16
  • 3
    Scientific notation is a display choice, not a data type issue. – hpaulj May 08 '20 at 18:25
  • Does this answer your question? [How to pretty-print a numpy.array without scientific notation and with given precision?](https://stackoverflow.com/questions/2891790/how-to-pretty-print-a-numpy-array-without-scientific-notation-and-with-given-pre) – Mad Physicist May 08 '20 at 18:47

2 Answers2

2

This is just the way the output gets printed out, internally, it is most likely represented as a floating point or double precision floating point. If you want to explicitly set the datatype of an array, you can use a named argument dtype.

import numpy as np
arr = np.array([1, 2, 3], dtype='float')

If you want to control how the data is printed in the terminal, refer to this.

Papooch
  • 1,372
  • 11
  • 17
2

What you are looking for is:

np.set_printoptions(suppress=True)

However, keep that in mind that it is just printing style. Internally, they are all stored in floating point (includes mantissa and exponent) format. Also, note that if the ratio of largest number to smallest number is larger than mantissa size can handle (which I think is around 51 bits), it is going to force scientific notation even with setting suppress=True.

sample code:

a = np.array([1.234,0.0000002, 1000000])

np.set_printoptions(suppress=True)
[      1.234           0.0000002 1000000.       ]

You can add floatmode argument to fill in the blanks with 0s (it sets different styles of printing float numbers):

np.set_printoptions(suppress=True,floatmode='maxprec_equal')
[     1.2340000      0.0000002 100000.0000000]

or

np.set_printoptions(suppress=True,floatmode='fixed')
[     1.23400000      0.00000020 100000.00000000]

and if you add precision to it:

np.set_printoptions(suppress=True,floatmode='maxprec',precision=2)
[     1.23      0.   100000.  ]
Ehsan
  • 12,072
  • 2
  • 20
  • 33