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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With