Strange value formatting when converting lists to numpy array

Viewed 38

I'm experiencing something strange when converting a regular array (lists within a list), to a numpy.array. All the values seem to be normalized in a strange manner. This is my regular list:

print(output)
print(type(output))

result:
[[0, 301227, 0.86, 0.46, -3.55, 0.53, 135.96, 4, 0.49, 0.33, 0.33 ......
<class 'list'>

and when I do the same with print(np.array(output)), this is the result:

[[ 0.00000e+00  3.01227e+05  8.60000e-01  4.60000e-01 -3.55000e+00 5.30000e-01.....
<class 'numpy.ndarray'>

I've never encountered this before. Hope someone can shed some light Cheers

1 Answers

The values remain intact, it just another form of representation called E notation,

The number mEn is divided into two parts, before and after the e:

  1. m The part to the left, is the multiplier
  2. n The part to the right, is the power of ten to be multiplied by

e.g.

3.01227e+05 = 3.01227 * 10^5 = 301227

You can suppress the use of E notation for small numbers using set_printoptions:

np.set_printoptions(suppress=True)

Flag suppress from the docs:

If True, always print floating point numbers using fixed point notation, in which case numbers equal to zero in the current precision will print as zero. If False, then scientific notation is used when absolute value of the smallest number is < 1e-4 or the ratio of the maximum absolute value to the minimum is > 1e3. The default is False.

Related