因此,我正在寻找对 numpy 数组中的所有数字进行四舍五入的方法。我发现了 2 个类似的函数,numpy.round 和 numpy.around。对于像我这样的初学者来说,两者都采取了看似相同的论点。
那么这两者之间有什么区别:
def round_(a, decimals=0, out=None):
"""
Round an array to the given number of decimals.
Refer to `around` for full documentation.
See Also
--------
around : equivalent function
"""
return around(a, decimals=decimals, out=out)
主要区别在于,
round
是ufunc
类的ndarray
,而np.around
是模块级函数。
从功能上来说,它们都是等价的,因为它们做同样的事情——均匀地将浮点数舍入到最接近的整数。
ndarray.round
从其源代码中调用 around
。