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

后端 未结 14 2348
臣服心动
臣服心动 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:34

    The numpy arrays have the method round(precision) which return a new numpy array with elements rounded accordingly.

    import numpy as np
    
    x = np.random.random([5,5])
    print(x.round(3))
    

提交回复
热议问题