0

I am trying to create an object that consist of an array of float numbers using numpy and display it. However whenever I display it the floats shows up as much smaller numbers.

class Ranges(object):
    def __init__(self, ranges):
        self.ranges = ranges

    def display(self):
        print(self.ranges)

def main():
    ranges_array = np.array([0.7, 677, 2.2, 150.2, 700, 0.002, 0.006, 7])
    ranges_object = Ranges(ranges_object)

    ranges_object.display()


if __name__ == "__main__":
    main()

The result I am getting looks as following:

[7.000e-01 6.770e+02 2.200e+00 1.502e+02 7.000e+02 2.000e-03 6.000e-03
7.000e+00]

Does anyone knows why it display the results like this or what am I doing wrong?

Thank you very much.

anonymous
  • 11
  • 2
  • 1
    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) – Dan Mar 02 '20 at 17:02
  • Those are the same numbers, just a different format! – hpaulj Mar 02 '20 at 17:17
  • Thank you Dan, that helped! – anonymous Mar 02 '20 at 17:35

1 Answers1

0

The default settings of numpy cause your array to be displayed in scientific notation. You can use the option suppress=True to suppress scientific notation, as in:

import numpy as np
np.set_printoptions(suppress=True)
print(np.array([0.7, 677, 2.2, 150.2, 700, 0.002, 0.006, 7]))

You then get the desired output:

[ 0.7 677. 2.2 150.2 700. 0.002 0.006 7. ]

maurera
  • 1,519
  • 1
  • 15
  • 28