Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing interpolate in scipy 0.17

I am using scipy 0.17.1 and numpy 1.11.1. I am getting an error when trying to use interpolate, even if the subpackage interpolate should be included in my version (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)

Results in error:

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'

Can I use the interpolate module without upgrading scipy?

like image 279
FLab Avatar asked Aug 11 '17 11:08

FLab


People also ask

What is Scipy interpolate in Python?

Interpolation is a technique of constructing data points between given data points. The scipy. interpolate is a module in Python SciPy consisting of classes, spline functions, and univariate and multivariate interpolation classes. Interpolation is done in many ways some of them are : 1-D Interpolation.

What is interpolate interp1d?

The interp1d() function of scipy. interpolate package is used to interpolate a 1-D function. It takes arrays of values such as x and y to approximate some function y = f(x) and then uses interpolation to find the value of new points.

Is interp1d linear interpolation?

One-dimensional linear interpolation for monotonically increasing sample points. Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x. The x-coordinates at which to evaluate the interpolated values.


1 Answers

As per the scipy source - you need to explicitly import the subpackage:

Subpackages

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

So changing (or adding)

import scipy.interpolate

should fix it for you

like image 124
Gavin Avatar answered Oct 18 '22 08:10

Gavin