python - scipy 0.17 中缺少插值

标签 python numpy scipy

我正在使用 scipy 0.17.1numpy 1.11.1。 我在尝试使用 interpolate 时遇到错误,即使子包 interpolate 应该包含在我的版本中 (docs)

import numpy as np
import scipy
x = np.linspace(0, 2*np.pi, 1000)
y = np.sin(x) + 0.01*np.random.randn(1, 1000)
y = scipy.interpolate.PchipInterpolator(x, y)

错误结果:

Traceback (most recent call last):
  File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-110-7dfbae0fdab5>", line 5, in <module>
    y = scipy.interpolate.PchipInterpolator(x, y)
AttributeError: 'module' object has no attribute 'interpolate'

我可以在不升级 scipy 的情况下使用 interpolate 模块吗?

最佳答案

根据 scipy 源 - 您需要显式导入子包:

Subpackages

Using any of these subpackages requires an explicit import. For example, import scipy.cluster.

所以改变(或添加)

import scipy.interpolate

应该为你解决它

关于python - scipy 0.17 中缺少插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45634350/

相关文章:

python - 烤宽面条的 csv 文件中的 numpy 数组

python - 使用 python 中的矢量化解决方案计算最大绘制

Python 对数组的每一列应用函数

python - 数据功能在其域的一小部分上的多重集成 - 准确性和效率

python - 使用 numpy 或 pandas 的时间序列

python - 如何迭代以下方程以确定根

python - 系统找不到 `edx-dl`模块中指定的文件

python - 删除滚动条以显示完整表格

python - 如何同时支持 argparse 和 optparse?

python - 属性错误 : 'module' object has no attribute 'maketrans' while running cProfile