【问题标题】:python3: numpy works, but numpy.integrate doesn'tpython3: numpy 有效,但 numpy.integrate 无效
【发布时间】:2017-05-18 21:27:08
【问题描述】:

我在python3 中使用numpy 进行数学项目。今天,我想使用numpy.integrate.quad,但是您可以在下面看到错误和进一步的尝试。 import numpy 总是有效。那到底是怎么回事?

$ python
Python 3.6.1 (default, Mar 27 2017, 00:27:06) 
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import numpy.integrate as integrate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy.integrate'
>>> import scipy.integrate as integrate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'scipy'
>>> from numpy import integrate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'integrate'
>>> from scipy import integrate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'scipy'
>>> from numpy.integrate import quad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy.integrate'
>>> from numpy import integrate.quad
  File "<stdin>", line 1
    from numpy import integrate.quad

Numpy 似乎安装正确,但我仍然无法使用 numpy.integrate。我在搞乱进口吗?

【问题讨论】:

  • 没有numpy.integrate.quad。再看看您链接的文档中列出的名称。
  • 我知道它在那里被列为scipy.integrate.quad。但正如您所见,使用scipy 代替numpy 也不起作用。您的评论对我没有建设性,您能否具体说明我做错了什么?
  • 安装 scipy,老兄。
  • 你说得对,不知道 scipy 和 numpy 是不同的模块。以为 numpy 包含了所有这些。谢谢,这解决了我的问题:)

标签: python numpy python-import


【解决方案1】:
from scipy.integrate import quad

numpy 没有integrate ;这些在交付的scipy 部分。

【讨论】:

  • 谢谢,我试过了,但我不知道我必须将scipy 作为一个单独的包安装:) 以为numpy 包含所有内容。
  • 这是一个庞大的学习过程。仔细检查 NumPy / SciPy 文档,现在您知道了问题的根源。
  • 谢谢,我会这样做的:)
猜你喜欢
  • 1970-01-01
  • 2012-12-20
  • 2020-06-14
  • 2017-01-08
  • 2012-05-08
  • 2017-03-15
  • 2014-10-30
  • 2011-03-08
  • 2013-11-27
相关资源
最近更新 更多