def __init__(self, x, y):
x = np.asarray(x, dtype=float)
y = np.asarray(y, dtype=float)
n = x.shape[0]
dx = np.diff(x)
dy = np.diff(y, axis=0)
dxr = dx.reshape([dx.shape[0]] + [1] * (y.ndim - 1))
c = np.empty((3, n - 1) + y.shape[1:])
if n > 2:
A = np.ones((2, n))
b = np.empty((n,) + y.shape[1:])
b[0] = 0
b[1:] = 2 * dy / dxr
s = solve_banded((1, 0), A, b, overwrite_ab=True, overwrite_b=True,
check_finite=False)
c[0] = np.diff(s, axis=0) / (2 * dxr)
c[1] = s[:-1]
c[2] = y[:-1]
else:
c[0] = 0
c[1] = dy / dxr
c[2] = y[:-1]
super(_QuadraticSpline, self).__init__(c, x)
评论列表
文章目录