Reputation: 71
I'm using interpolate.interp1d from Scipy to interpolate a 1d array in Python3. I would like to use it with numba, but scipy and this function are not supported. Is there an interpolation function supported by numba, or a way to do an interpolation with numba?
Upvotes: 4
Views: 4353
Reputation: 88236
You could use numpy
's interpolation function for 1d arrays. You have a list of the numpy functions supported by numba here:
numpy.interp() (only the 3 first arguments; requires NumPy >= 1.10)
If you can't get it to work, it's prbably the version of numba. Here's a working example using the same example as in np.interp
:
import numpy as np
from numba import njit
@njit
def interp_nb(x_vals, x, y):
return np.interp(xvals, x, y)
x = np.linspace(0, 2*np.pi, 10)
y = np.sin(x)
xvals = np.linspace(0, 2*np.pi, 50)
y_interp = interp_nb(xvals, x, y)
plt.figure(figsize=(10,6))
plt.plot(x, y, 'o')
plt.plot(xvals, y_interp, '-x')
numba.__version__
# '0.43.1'
np.__version__
# '1.18.1'
Upvotes: 5