插值 - Numba
Interpolation - Numba
我正在使用 Scipy 中的 interpolate.interp1d 在 Python3 中插入一维数组。我想将它与 numba 一起使用,但不支持 scipy 和此功能。是否有numba支持的插值函数,或者用numba进行插值的方法?
您可以对一维数组使用 numpy
的插值函数。您有 numba here:
支持的 numpy 函数列表
numpy.interp() (only the 3 first arguments; requires NumPy >= 1.10)
如果你不能让它工作,它可能是 numba 的版本。这是一个工作示例,使用与 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'
我正在使用 Scipy 中的 interpolate.interp1d 在 Python3 中插入一维数组。我想将它与 numba 一起使用,但不支持 scipy 和此功能。是否有numba支持的插值函数,或者用numba进行插值的方法?
您可以对一维数组使用 numpy
的插值函数。您有 numba here:
numpy.interp() (only the 3 first arguments; requires NumPy >= 1.10)
如果你不能让它工作,它可能是 numba 的版本。这是一个工作示例,使用与 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'