np.set_printoptions doesn't affect floats
See original GitHub issue>>> import numpy as np
>>> '%s' % np.array(1/3)
'0.3333333333333333'
>>> '%s' % np.array([1/3])
'[0.33333333]'
>>> np.set_printoptions(formatter={"float_kind": lambda x: "%.1f" % x})
>>> '%s' % np.array(1/3)
'0.3333333333333333'
>>> '%s' % np.array([1/3])
'[0.3]'
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
python - printoptions formatter not working for a single element ...
set_printoptions control how NumPy prints arrays. They do not affect how NumPy scalars (such as numpy.complex128 , numpy.float32 , etc) are ...
Read more >numpy.set_printoptions — NumPy v1.24 Manual
If True, always print floating point numbers using fixed point notation, in which case numbers equal to zero in the current precision will...
Read more >[Numpy-discussion] set_printoptions precision and single floats
doesn't affect single floats, even >> if they are numpy floats rather than Python floats. Is this a bug or is >> there...
Read more >numpy.set_printoptions — NumPy v1.10 Manual
formatter is always reset with a call to set_printoptions. Examples. Floating point precision can be set: >>> >>> np.
Read more >Numpy Random - angela1c.com
Explain the use of the numpy.random package in Python including detailed ... __version__ ) # '1.16.2' #np.set_printoptions(formatter={'float': lambda x: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A simpler reproduction is:
@ahaldane, do you think this is a feature (full precision is always shown for scalars) or an omission?
For the record, this behavior goes back as far as numpy 1.0.1, and probably before.
#9201 shows our attempts to update the str/repr of 0d arrays and why we had to keep this behavior. As I recall it was due to people expecting that
str
applied to a 0d array ofS
orU
dtype would always give back the string itself.