1

I tried to set np.set_printoptions(precision=100) in python but the output is still something like -0.00510610862213

Is there anyway to display e.g. 100 digits?

user26143
  • 177
  • 1
  • 7

1 Answers1

4

You can change the display precision up to a point. For example, looking below we can change the number of digits displayed up to a point after which no more digits are displayed.

In [1]: import numpy as np
In [2]: np.random.seed(42)
In [3]: a = np.random.randn(1,1)
In [4]: a
Out[4]: array([[ 0.49671415]])

In [5]: np.set_printoptions(precision=4)
In [6]: a
Out[6]: array([[ 0.4967]])

In [7]: np.set_printoptions(precision=54)
In [8]: a
Out[8]: array([[ 0.4967141530112326730517224859795533120632171630859375]])

In [9]: np.set_printoptions(precision=55)
In [10]: a
Out[10]: array([[ 0.4967141530112326730517224859795533120632171630859375]])

But, it is unclear why you would want to do this since as @user2357112 eluded to, this will not change the numerical precision. The default in numpy is storing 64 bit floats, which as described here, are only precise up to at most 15 significant digits

This gives 15–17 significant decimal digits precision. If a decimal string with at most 15 significant digits is converted to IEEE 754 double precision representation and then converted back to a string with the same number of significant digits, then the final string should match the original. If an IEEE 754 double precision is converted to a decimal string with at least 17 significant digits and then converted back to double, then the final number must match the original.

An example of this is illustrated using

In [11]: np.float64('0.454125401')
Out[11]: 0.45412540099999998
mgilbert
  • 3,495
  • 4
  • 22
  • 39