我正在使用scipy 0.17.1numpy 1.11.1
尝试使用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'

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

最佳答案

根据scipy源-需要显式导入子包:
子包
使用这些子包需要显式导入。例如,
import scipy.cluster
所以改变(或增加)

import scipy.interpolate

应该给你修好的

07-24 09:52
查看更多