首页 > 解决方案 > 在python中计算长数字时出错

问题描述

我正在尝试计算一些大数的平方根,例如:

np.sqrt(324524513452345134623454326)

但我收到以下错误:

>>> import numpy as np
>>> np.sqrt(324524513452345134623454326)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'sqrt'
>>> np
<module 'numpy' from '/.../site-packages/numpy/__init__.py'>
>>> np.sqrt(324524)
569.6700799585669

注意:np不是整数,它仍然绑定到numpy模块!对于较小的整数,函数调用工作得很好。

我正在使用 python 3.6。

标签: pythonnumpy

解决方案


推荐阅读