Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print array as specific format?

I have an array formatted like this:

[-22.99253267 -83.23210952  77.71126322  43.99377722 -41.75731176 89.02862477]

I would like to print this array to receive this result

[-22.992 -83.232  77.711  43.993 -41.757 89.028]

I know It will be a similar result if I use np.set_printoptions(precision=3), but I would like to know how to receive this result using 9.3f.

like image 485
J. Park Avatar asked Oct 24 '25 02:10

J. Park


1 Answers

To print the data in column :

for data in x:
    print '{:9.3f}'.format(data)

or

To print the data in row : (don't forget import sys)

for data in x:
    sys.stdout.write('{:9.3f}'.format(data))
like image 185
PilouPili Avatar answered Oct 26 '25 19:10

PilouPili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!