Display More Than 16 Digits In Numpy
Solution 1:
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
Post a Comment for "Display More Than 16 Digits In Numpy"