How to pretty-print a numpy.array without scientific notation and with given precision?

后端 未结 14 2174
臣服心动
臣服心动 2020-11-22 04:28

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
         


        
14条回答
  •  不思量自难忘°
    2020-11-22 04:31

    Was surprised to not see around method mentioned - means no messing with print options.

    import numpy as np
    
    x = np.random.random([5,5])
    print(np.around(x,decimals=3))
    
    Output:
    [[0.475 0.239 0.183 0.991 0.171]
     [0.231 0.188 0.235 0.335 0.049]
     [0.87  0.212 0.219 0.9   0.3  ]
     [0.628 0.791 0.409 0.5   0.319]
     [0.614 0.84  0.812 0.4   0.307]]
    

提交回复
热议问题