其他分享
首页 > 其他分享> > 为什么numpy先验的整数参数大于2 ^ 64-1会给出“无属性”错误?

为什么numpy先验的整数参数大于2 ^ 64-1会给出“无属性”错误?

作者:互联网

奇怪的是,np.log(2 ** 64-1)返回浮点数44.3614196

但是np.log(2 ** 64)返回

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'log' 

问题:

>为什么numpy会拒绝大于2 ^ 64-1的参数?
>为什么会出现AttributeError错误,而不是抱怨参数的大小?

fyi:其他numpy超越函数(sqrt,log10,cos …)的相同行为

解决方法:

NumPy没有足够大的本地整数dtype来容纳2 ** 64,因此它得到对象dtype处理. numpy.log的object dtype处理是在对象上查找日志方法并调用它,这就是AttributeError的来源.

标签:python-3-x,python,numpy
来源: https://codeday.me/bug/20191210/2104594.html