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

18

所以,我在寻找一种方法将numpy数组中的所有数字四舍五入。我找到了两个类似的函数,numpy.round和numpy.around。对于像我这样的初学者来说,它们都使用看起来相同的参数。

那么,这两者在以下方面有什么区别:

  • 常规差异
  • 速度
  • 精度
  • 实际应用
3个回答

13

它们是完全相同的函数:

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)

1
文档说明:np.round - 将数组四舍五入到给定的小数位数。而对于np.around - 均匀地四舍五入到给定的小数位数。 - DuttaA

11

主要的区别在于 roundndarray 类的一个 ufunc,而 np.around 是一个模块级函数。

从功能上看,它们都是等价的,因为它们做相同的事情 - 把浮点数均匀地四舍五入到最接近的整数。ndarray.round 在其源代码中调用了 around


什么是ufunc? - DuttaA
5
“通用函数”是ndarray的一种方法,它对数组进行逐元素操作。 - cs95
谢谢...感谢帮助。 - DuttaA
@cs95,“evenly round”是什么意思?与“round”的区别是什么? - Chong Onn Keat

0
截至2023年8月,doc现在表示aroundround的别名。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接