Python 内置round()函数使用numpy更改其行为

Python 内置round()函数使用numpy更改其行为,python,numpy,Python,Numpy,考虑以下代码: >>> help(round) round(number, ndigits=None) Round a number to a given precision in decimal digits. The return value is an integer if ndigits is omitted or None. Otherwise the return value has the same type as the number.

考虑以下代码:

>>> help(round)
round(number, ndigits=None)
    Round a number to a given precision in decimal digits.
    The return value is an integer if ndigits is omitted or None.  Otherwise
    the return value has the same type as the number.  ndigits may be negative.
>>> type(t)
<class 'numpy.float64'>
>>> type(round(t))
<class 'numpy.float64'>
>>> t=2.3
>>> type(t)
<class 'float'>
>>> type(round(t))
<class 'int'>

因此,当内置的
round
函数应用于numpy数据时,它似乎被
numpy.round
神奇地取代了。怎么可能呢?

不一定。它清楚地表明返回类型与输入类型相同。NumPy bug tracker上有各种各样的问题需要讨论。例如
>>> import numpy as np
>>> type(np.round(1.1))
<class 'numpy.float64'>