numpy.round和numpy.around之间的区别

Dut*_*taA 5 python arrays numpy rounding

因此,我正在寻找舍入numpy数组中所有数字的方法。我发现了2个类似的函数numpy.round和numpy.around。对于像我这样的初学者来说,两者似乎都存在相同的观点。

那么,这两个方面有什么区别:

  • 一般差异
  • 速度
  • 准确性
  • 在实践中使用

cs9*_*s95 8

的主要区别在于,roundufunc所述的ndarray类,而np.around是一个模块级功能。

从功能上讲,它们是等效的,因为它们做同样的事情——将浮点数均匀地舍入到最接近的整数。从其源代码中ndarray.round调用around

  • @DuttaA“通用功能”。这些是 `ndarray` 的方法,它们对数组进行元素操作。 (5认同)

Ble*_*der 7

它们是完全相同的功能

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)
Run Code Online (Sandbox Code Playgroud)