Generate a Pseudo-Vandermonde matrix of given degree and x, y, z complex array of points in Python

To generate a pseudo-Vandermonde matrix of given degree and sample points (x, y, z), use the polynomial.polyvander3d() function in NumPy. This method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z).

Syntax

numpy.polynomial.polynomial.polyvander3d(x, y, z, deg)

Parameters

  • x, y, z − 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.
  • deg − List of maximum degrees of the form [x_deg, y_deg, z_deg]

Creating Complex Arrays

First, let's create arrays of complex point coordinates and examine their properties ?

import numpy as np
from numpy.polynomial.polynomial import polyvander3d

# Create arrays of point coordinates with complex numbers
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3.+3.j])

# Display the arrays
print("Array x:", x)
print("Array y:", y)
print("Array z:", z)

# Display the datatypes
print("\nDatatype of x:", x.dtype)
print("Datatype of y:", y.dtype)
print("Datatype of z:", z.dtype)

# Check dimensions and shapes
print("\nShapes - x:", x.shape, "y:", y.shape, "z:", z.shape)
Array x: [-2.+2.j -1.+2.j]
Array y: [0.+2.j 1.+2.j]
Array z: [2.+2.j 3.+3.j]

Datatype of x: complex128
Datatype of y: complex128
Datatype of z: complex128

Shapes - x: (2,) y: (2,) z: (2,)

Generating the Pseudo-Vandermonde Matrix

Now let's generate a pseudo-Vandermonde matrix with degrees [2, 3, 4] for x, y, and z respectively ?

import numpy as np
from numpy.polynomial.polynomial import polyvander3d

# Create complex arrays
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3.+3.j])

# Set degrees for x, y, z
x_deg, y_deg, z_deg = 2, 3, 4

# Generate the pseudo-Vandermonde matrix
result = polyvander3d(x, y, z, [x_deg, y_deg, z_deg])

print("Pseudo-Vandermonde matrix shape:", result.shape)
print("Matrix (showing first 5 columns):")
print(result[:, :5])
Pseudo-Vandermonde matrix shape: (2, 60)
Matrix (showing first 5 columns):
[[ 1.000e+00+0.000e+00j  2.000e+00+2.000e+00j  0.000e+00+8.000e+00j
  -1.600e+01+1.600e+01j -6.400e+01+0.000e+00j]
 [ 1.000e+00+0.000e+00j  3.000e+00+3.000e+00j  0.000e+00+1.800e+01j
  -5.400e+01+5.400e+01j -3.240e+02+0.000e+00j]]

Understanding the Output

The resulting matrix has dimensions based on the degrees specified. For degrees [2, 3, 4], the number of columns is (2+1) × (3+1) × (4+1) = 3 × 4 × 5 = 60 ?

import numpy as np
from numpy.polynomial.polynomial import polyvander3d

# Simple example with smaller degrees
x = np.array([1+1j, 2+0j])
y = np.array([0+1j, 1+1j])
z = np.array([1+0j, 0+1j])

# Use smaller degrees for clearer output
result = polyvander3d(x, y, z, [1, 1, 1])

print("Matrix with degrees [1, 1, 1]:")
print("Shape:", result.shape)
print("Matrix:")
print(result)
Matrix with degrees [1, 1, 1]:
Shape: (2, 8)
Matrix:
[[1.+0.j 1.+0.j 0.+1.j 0.+1.j 1.+1.j 1.+1.j 0.+1.j 0.+1.j]
 [1.+0.j 0.+1.j 1.+1.j 0.+1.j 2.+0.j 0.+2.j 2.+2.j 0.+2.j]]

Key Points

  • The function automatically converts input arrays to complex128 when complex numbers are present
  • All input arrays (x, y, z) must have the same shape
  • The degree parameter determines the polynomial degree for each variable
  • Output matrix columns = (x_deg+1) × (y_deg+1) × (z_deg+1)

Conclusion

The polyvander3d() function generates pseudo-Vandermonde matrices for three-dimensional polynomial fitting with complex numbers. It's useful for multivariate polynomial interpolation and regression with complex data points.

Updated on: 2026-03-26T19:40:36+05:30

194 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements