MCPcopy Create free account
hub / github.com/numpy/numpy / _vander_nd

Function _vander_nd

numpy/polynomial/polyutils.py:381–447  ·  view source on GitHub ↗

r""" A generalization of the Vandermonde matrix for N dimensions The result is built by combining the results of 1d Vandermonde matrices, .. math:: W[i_0, \ldots, i_M, j_0, \ldots, j_N] = \prod_{k=0}^N{V_k(x_k)[i_0, \ldots, i_M, j_k]} where .. math:: N &= \tex

(vander_fs, points, degrees)

Source from the content-addressed store, hash-verified

379
380
381def _vander_nd(vander_fs, points, degrees):
382 r"""
383 A generalization of the Vandermonde matrix for N dimensions
384
385 The result is built by combining the results of 1d Vandermonde matrices,
386
387 .. math::
388 W[i_0, \ldots, i_M, j_0, \ldots, j_N] = \prod_{k=0}^N{V_k(x_k)[i_0, \ldots, i_M, j_k]}
389
390 where
391
392 .. math::
393 N &= \texttt{len(points)} = \texttt{len(degrees)} = \texttt{len(vander\_fs)} \\
394 M &= \texttt{points[k].ndim} \\
395 V_k &= \texttt{vander\_fs[k]} \\
396 x_k &= \texttt{points[k]} \\
397 0 \le j_k &\le \texttt{degrees[k]}
398
399 Expanding the one-dimensional :math:`V_k` functions gives:
400
401 .. math::
402 W[i_0, \ldots, i_M, j_0, \ldots, j_N] = \prod_{k=0}^N{B_{k, j_k}(x_k[i_0, \ldots, i_M])}
403
404 where :math:`B_{k,m}` is the m'th basis of the polynomial construction used along
405 dimension :math:`k`. For a regular polynomial, :math:`B_{k, m}(x) = P_m(x) = x^m`.
406
407 Parameters
408 ----------
409 vander_fs : Sequence[function(array_like, int) -> ndarray]
410 The 1d vander function to use for each axis, such as ``polyvander``
411 points : Sequence[array_like]
412 Arrays of point coordinates, all of the same shape. The dtypes
413 will be converted to either float64 or complex128 depending on
414 whether any of the elements are complex. Scalars are converted to
415 1-D arrays.
416 This must be the same length as `vander_fs`.
417 degrees : Sequence[int]
418 The maximum degree (inclusive) to use for each axis.
419 This must be the same length as `vander_fs`.
420
421 Returns
422 -------
423 vander_nd : ndarray
424 An array of shape ``points[0].shape + tuple(d + 1 for d in degrees)``.
425 """
426 n_dims = len(vander_fs)
427 if n_dims != len(points):
428 raise ValueError(
429 f"Expected {n_dims} dimensions of sample points, got {len(points)}")
430 if n_dims != len(degrees):
431 raise ValueError(
432 f"Expected {n_dims} dimensions of degrees, got {len(degrees)}")
433 if n_dims == 0:
434 raise ValueError("Unable to guess a dtype or shape when no points are given")
435
436 # convert to the same shape and type
437 points = tuple(np.array(tuple(points), copy=False) + 0.0)
438

Callers 1

_vander_nd_flatFunction · 0.85

Calls 2

_nth_sliceFunction · 0.85
reduceMethod · 0.45

Tested by

no test coverage detected