numpy.polynomial.polynomial.polyvander2d#

polynomial.polynomial.polyvander2d(x, y, deg)[source]#

Pseudo-Vandermonde matrix of given degrees.

Returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y). The pseudo-Vandermonde matrix is defined by

\[V[..., (deg[1] + 1)*i + j] = x^i * y^j,\]

where 0 <= i <= deg[0] and 0 <= j <= deg[1]. The leading indices of V index the points (x, y) and the last index encodes the powers of x and y.

If V = polyvander2d(x, y, [xdeg, ydeg]), then the columns of V correspond to the elements of a 2-D coefficient array c of shape (xdeg + 1, ydeg + 1) in the order

\[c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...\]

and np.dot(V, c.flat) and polyval2d(x, y, c) will be the same up to roundoff. This equivalence is useful both for least squares fitting and for the evaluation of a large number of 2-D polynomials of the same degrees and sample points.

Parameters:
x, yarray_like

Arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays.

deglist of ints

List of maximum degrees of the form [x_deg, y_deg].

Returns:
vander2dndarray

The shape of the returned matrix is x.shape + (order,), where \(order = (deg[0]+1)*(deg([1]+1)\). The dtype will be the same as the converted x and y.

Examples

The 2-D pseudo-Vandermonde matrix of degree [1, 2] and sample points x = [-1, 2] and y = [1, 3] is as follows:

>>> from numpy.polynomial import polynomial as P
>>> x = np.array([-1, 2])
>>> y = np.array([1, 3])
>>> m, n = 1, 2
>>> deg = np.array([m, n])
>>> V = P.polyvander2d(x=x, y=y, deg=deg)
>>> V
array([[ 1.,  1.,  1., -1., -1., -1.],
       [ 1.,  3.,  9.,  2.,  6., 18.]])

We can verify the columns for any 0 <= i <= m and 0 <= j <= n:

>>> i, j = 0, 1
>>> V[:, (deg[1]+1)*i + j] == x**i * y**j
array([ True,  True])

The (1D) Vandermonde matrix of sample points x and degree m is a special case of the (2D) pseudo-Vandermonde matrix with y points all zero and degree [m, 0].

>>> P.polyvander2d(x=x, y=0*x, deg=(m, 0)) == P.polyvander(x=x, deg=m)
array([[ True,  True],
       [ True,  True]])