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

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

    Yet another option is to use the decimal module:

    import numpy as np
    from decimal import *
    
    arr = np.array([  56.83,  385.3 ,    6.65,  126.63,   85.76,  192.72,  112.81, 10.55])
    arr2 = [str(Decimal(i).quantize(Decimal('.01'))) for i in arr]
    
    # ['56.83', '385.30', '6.65', '126.63', '85.76', '192.72', '112.81', '10.55']
    

提交回复
热议问题