Is there a way to force numpy.set_printoptions to show the exact float value?

Viewed 210

Following question 59674518, is there a way for numpy.set_printoptions to ensure the EXACT float value is displayed, without displaying trailing zeros, and without knowing the value a priori? I have tried all 4 float mode options to no avail. Just trying to understand; no ultimate objective. (I think it can't be done, if so, what is the rational? Just a feature not in existence [yet]?).

Mac_3.2.57$python3
Python 3.7.1 (default, Nov  6 2018, 18:45:35) 
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.set_printoptions(precision=15)
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 11)
array([0.0107421875])
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.278255462646484e-07])
>>> print("%.45f" % (numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)).item(0))
0.000000327825546264648437500000000000000000000
>>> numpy.set_printoptions(floatmode="fixed")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.278255462646484e-07])
>>> numpy.set_printoptions(floatmode="unique")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.2782554626464844e-07])
>>> numpy.set_printoptions(floatmode="maxprec")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.278255462646484e-07])
>>> numpy.set_printoptions(floatmode="maxprec_equal")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.278255462646484e-07])
>>> numpy.set_printoptions(precision=45,floatmode="fixed")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.278255462646484375000000000000000000000000000e-07])
>>> numpy.set_printoptions(precision=45,floatmode="unique")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.2782554626464844e-07])
>>> numpy.set_printoptions(precision=45,floatmode="maxprec")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.2782554626464844e-07])
>>> numpy.set_printoptions(precision=45,floatmode="maxprec_equal")
>>> numpy.array([22.0], dtype=numpy.float64) / (2 ** 26)
array([3.2782554626464844e-07])
>>> 
0 Answers
Related