set_printoptions does not work with numpy structured arrays
See original GitHub issueI want to set the print precision for a numpy structured array, but it does not seem to work.
H = np.zeros(1, dtype=[('x','float',2),('f','float')])
H['x']= np.random.uniform(0,1,(1,2))
H['f']= np.random.uniform(0,1)
np.set_printoptions(precision=3)
print(H)
leaves
[([0.5928384015048476, 0.6187004067605606], 0.2981617279773586)]
not
[([0.593, 0.619], 0.298)]
as I expected. Printing H[‘x’] works (because that’s not a structured array), but I have many fields in my structured array and I don’t want to have to print each one when monitoring the progress of my code.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:9
- Comments:7 (3 by maintainers)
Top Results From Across the Web
set_printoptions for numpy array doesn't work ... - Stack Overflow
Try numpy.array2string which takes ndarray as input and you can set precision. Scroll down in below documentation link for examples.
Read more >numpy.set_printoptions — NumPy v1.24 Manual
Set printing options. These options determine the way floating point numbers, arrays and other NumPy objects are displayed. ... If not None, the...
Read more >numpy.fromregex — NumPy v1.23 Manual
Construct an array from a text file, using regular expression parsing. The returned array is always a structured array, and is constructed from...
Read more >numpy.loadtxt — NumPy v1.24 Manual
When used with a structured data-type, arrays are returned for each field. Default is False. ndminint, optional. The returned array will have at...
Read more >NumPy quickstart — NumPy v1.25.dev0 Manual
To work the examples, you'll need matplotlib installed in addition to NumPy. ... Note that numpy.array is not the same as the Standard...
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 FreeTop 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
Top GitHub Comments
Numpy has no concept of a “mixed” array, only of
object
arrays containing elements of unknown types. Your array would probably work better as a structured array (what this issue is actually about), because then numpy keeps track of the type of each column separately.Thank you Eric!