I am working with masked numpy arrays and trying to print them out in a nice way for debugging purposes. I am setting the print options as below, but the output is not what I expect.
import numpy as np
np.set_printoptions(formatter={'float_kind': lambda x: "{0:0.3f}".format(x)})
x = np.random.uniform(size=(4,4))
xm = np.ma.array(x, mask=np.random.randint(0,2,size=(4,4)))
print(x)
print(xm)
The output:
[[0.877 0.504 0.518 0.156]
[0.439 0.028 0.863 0.738]
[0.516 0.614 0.439 0.597]
[0.164 0.953 0.427 0.923]]
[[0.876728440179007 -- -- 0.1564739272031952]
[-- 0.028450171766788213 -- --]
[-- -- -- 0.5972907957825376]
[-- 0.95334588487527 0.4273250291466033 --]]
The masked array does not get printed to 3dp. Is this feature missing from numpy.ma? If anyone knows a work around (short of writing my own print function) it would be much appreciated!