【问题标题】:Missing interpolate in scipy 0.17scipy 0.17 中缺少插值
【发布时间】:2017-08-11 11:40:58
【问题描述】:

我正在使用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 模块吗?

【问题讨论】:

  • 应该可用。也许你必须import scipy.interpolate

标签: python numpy scipy


【解决方案1】:

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

子包

使用这些子包中的任何一个都需要显式导入。例如, import scipy.cluster.

所以改变(或增加)

import scipy.interpolate

应该为你解决它

【讨论】:

  • 只是想知道您或其他人是否碰巧知道为什么 scipy 是这样的。 Numpy 不是:我可以调用 numpy.random.rand 而无需显式导入 numpy.random。
  • @saintsfan342000 - 这个question 和答案可能会有所启发:特别是这个comment 可能有关键点(即设计决策)
猜你喜欢
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多