Truncating decimal digits numpy array of floats

后端 未结 2 1617
隐瞒了意图╮
隐瞒了意图╮ 2020-12-11 02:22

I want to truncate the float values within the numpy array, for .e.g.

2.34341232 --> 2.34 

I read the post truncate floating point but i

2条回答
  •  甜味超标
    2020-12-11 03:01

    Use numpy.round:

    import numpy as np
    a = np.arange(4) ** np.pi
    a
    => array([  0.        ,   1.        ,   8.82497783,  31.5442807 ])
    a.round(decimals=2)
    => array([  0.  ,   1.  ,   8.82,  31.54])
    

提交回复
热议问题