Why is there strange scientific notation in NumPy?

Whenever I print the array inside the loop, it displays it as

[  1.170e-01   2.187e+08   2.000e-02]

      

Although I used the following code

np.set_printoptions(suppress=True,precision=3)

      

After running the code, I will copy the same result as

a1=[  1.170e-01,   2.187e+08 ,  2.000e-02]
print a1

      

And it prints it correctly as

[0.117, 218700000.0, 0.02]

      

Obviously this is bad behavior in NumPy? Printing inside and outside the loop doesn't matter!

Actual code

ll = (calib_params+np.sqrt(np.diag(params[1])*residuals/(len(data_outsample)-3))*nstd)
ul = (calib_params-np.sqrt(np.diag(params[1])*residuals/(len(data_outsample)-3))*nstd)
print ll
print ul

      

I even tried np.round(ll,3)

and np.round(ul,3)

but unfortunately none of them work.

It is impossible to suppress the scientific display!

+3


source to share


1 answer


This is not specific to numpy, but to Python's floating point representation in general. You have encountered two different default behaviors (scientific notation and simple decimal point).

This describes how to format floating points as strings.

There is an entry in the topic here.

The following code formats a number to three decimal places:



print('%1.3f'% .333333333333333333333333)

      

Output

0.333

      

0


source







All Articles