I\'m curious, whether there is any way to print formatted numpy.arrays
, e.g., in a way similar to this:
x = 1.23456
print \'%.3f\' % x
>
The gem that makes it all too easy to obtain the result as a string (in today's numpy versions) is hidden in denis answer: np.array2string
>>> import numpy as np
>>> x=np.random.random(10)
>>> np.array2string(x, formatter={'float_kind':'{0:.3f}'.format})
'[0.599 0.847 0.513 0.155 0.844 0.753 0.920 0.797 0.427 0.420]'