bundles / scipy latest / scipy / interpolate / _dierckx / evaluate_ndbspline
built-in
scipy.interpolate._dierckx:evaluate_ndbspline
Summary
Evaluate an N-dim tensor product spline or its derivative.
Parameters
xi: ndarray, shape(npoints, ndim)npointsvalues to evaluate the spline at, each value is a point in anndim-dimensional space.t: ndarray, shape(ndim, max_len_t)Array of knots for each dimension. This array packs the tuple of knot arrays per dimension into a single 2D array. The array is ragged (knot lengths may differ), hence the real knots in dimension
daret[d, :len_t[d]].len_t: ndarray, 1D, shape (ndim,)Lengths of the knot arrays, per dimension.
k: tuple of ints, len(ndim)Spline degrees in each dimension.
nu: ndarray of ints, shape(ndim,)Orders of derivatives to compute, per dimension.
extrapolate: intWhether to extrapolate out of bounds or return nans.
c1r: ndarray, one-dimensionalFlattened array of coefficients. The original N-dimensional coefficient array
chas shape(n1, ..., nd, ...)where eachni == len(t[d]) - k[d] - 1, and the second '...' represents trailing dimensions ofc. In code, given the C-ordered arrayc,c1risc1 = c.reshape(c.shape[:ndim] + (-1,)); c1r = c1.ravel()num_c_tr: intThe number of elements of
c1r, which correspond to the trailing dimensions ofc. In code, this isc1 = c.reshape(c.shape[:ndim] + (-1,)); num_c_tr = c1.shape[-1].strides_c1: ndarray, one-dimensionalPre-computed strides of the
c1array. Note: These are data strides, not numpy-style byte strides. This array is equivalent to[stride // s1.dtype.itemsize for stride in s1.strides].indices_k1d: ndarray, shape((k+1)**ndim, ndim)Pre-computed mapping between indices for iterating over a flattened array of shape
[k[d] + 1) for d in range(ndim)and ndim-dimensional indices of the(k+1,)*ndimdimensional array. This is essentially a transposed version ofnp.unravel_index(np.arange((k+1)**ndim), (k+1,)*ndim).
Returns
out: ndarray, shape (npoints, num_c_tr)Output values of the b-spline at given
xipoints.
Notes
This function is essentially equivalent to the following: given an N-dimensional vector x = (x1, x2, ..., xN), iterate over the dimensions, form linear combinations of products, B(x1) * B(x2) * ... B(xN) of (k+1)**N b-splines which are non-zero at x.
Since b-splines are localized, the sum has (k+1)**N non-zero elements.
If i = (i1, i2, ..., iN) is a vector if intervals of the knot vectors, t[d, id] <= xd < t[d, id+1], for d=1, 2, ..., N, then the core loop of this function is nothing but
``` result = 0 iters = [range(i[d] - self.k[d], i[d] + 1) for d in range(ndim)] for idx in itertools.product(*iters): term = self.c[idx] * np.prod([B(x[d], self.k[d], idx[d], self.t[d]) for d in range(ndim)]) result += term ```
For efficiency reasons, we iterate over the flattened versions of the arrays.
Aliases
-
scipy.interpolate._dierckx.evaluate_ndbspline