I 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 each field does work, 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.
print(H['x'])also works (sinceH['x']is not a structured array), but it would be nice ifprint(H)used the precision set byset_printoptions(). This might be a numpy bug. You can create an issue here: github.com/numpy/numpy/issues (hit the green "New issue" button). - Warren Weckesser