0

I have these two arrays being printed.

array([[-7.00e+00, -9.00e+00,  0.00e+00,  1.60e+01,  0.00e+00, -9.00e+00, -7.00e+00, -1.20e+01],
       [-6.00e+00, -1.70e+01,  1.11e-15,  2.00e+01,  1.33e-15, -1.70e+01, -6.00e+00,  2.00e+00],
       [-3.00e+00, -1.90e+01,  1.00e+01,  2.80e+01,  1.00e+01, -1.90e+01, -3.00e+00,  2.40e+01],
       [ 6.00e+00,  0.00e+00,  1.40e+01,  1.60e+01,  1.40e+01,  1.78e-15,  6.00e+00,  2.40e+01],
       [-3.00e+00, -1.90e+01,  1.00e+01,  2.80e+01,  1.00e+01, -1.90e+01, -3.00e+00,  2.40e+01],
       [-6.00e+00, -1.70e+01, -1.11e-15,  2.00e+01,  4.44e-16, -1.70e+01, -6.00e+00,  2.00e+00],
       [-7.00e+00, -9.00e+00,  0.00e+00,  1.60e+01,  8.88e-16, -9.00e+00, -7.00e+00, -1.20e+01],
       [-1.40e+01, -2.20e+01,  6.00e+00,  3.20e+01,  6.00e+00, -2.20e+01, -1.40e+01, -4.00e+00]])
array([[ -9.96, -29.6 ,  -7.68,  47.32],
       [-11.7 , -17.86, -10.47,  25.97],
       [ 28.45, -22.42,  -9.69,  46.16],
       [ 42.94,  -2.22,  11.06,  40.59]])

When logging their type, they are both float64. I wonder why one as scientific notation and not the other. Also, how to set it to always have the second notation.

I have this on the top of my script

np.set_printoptions(linewidth=240, precision=2)

But apparently it is not holding for all cases.

4
  • Do you somehow declare the arrays to be numpy? Commented Aug 21, 2020 at 3:17
  • Yes. Both of them come from processing numpy arrays. Commented Aug 21, 2020 at 3:20
  • 1
    And I can also confirm with type(out1) and type(out2) returning numpy.ndarray Commented Aug 21, 2020 at 3:21
  • 1
    numpy uses scientific notation when the range of values is wide. Display, for example, the first row which does not have any e-15 values. Commented Aug 21, 2020 at 3:32

1 Answer 1

1

Some of the elements of the first array are tiny, like this one:

-1.11e-15

The e-15 means "times 10 to the power of -15". That'd take a ton of digits to display in ordinary positional notation, so NumPy switches to scientific notation. For layout consistency, this applies to the whole array.

You can have NumPy's array printing logic instead treat these values as (appropriately signed) zero by setting the suppress print option to True:

numpy.set_printoptions(suppress=True)
Sign up to request clarification or add additional context in comments.

1 Comment

Could somehow use suppress to round it and at the same time keep a coupe decimal places for precision? Suppressing produces array([[ -7., -9., 0., 16., 0., -9., -7., -12.], ....]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.