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

PythonNumpyServer Side ProgrammingProgramming

To generate a pseudo Vandermonde matrix of given degree and x, y, z sample points, use the polynomial.polyvander3d() in Python Numpy. The method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z). The parameter, x, y, z are the 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. The parameter, deg is the list of maximum degrees of the form [x_deg, y_deg, z_deg].

Steps

At first, import the required libraries −

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

Create arrays of point coordinates, all of the same shape using the numpy.array() method −

x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])

Display the arrays −

print("Array1...
",x) print("
Array2...
",y) print("
Array3...
",z)

Display the datatype −

print("
Array1 datatype...
",x.dtype) print("
Array2 datatype...
",y.dtype) print("
Array3 datatype...
",z.dtype)

Check the Dimensions −

print("
Dimensions of Array1...
",x.ndim) print("
Dimensions of Array2...
",y.ndim) print("
Dimensions of Array3...
",z.ndim)

Check the Shape −

print("
Shape of Array1...
",x.shape) print("
Shape of Array2...
",y.shape) print("
Shape of Array3...
",z.shape)

To generate a pseudo Vandermonde matrix of given degree and x, y, z sample points, use the polynomial.polyvander3d() −

x_deg, y_deg, z_deg = 2, 3, 4
print("
Result...
",polyvander3d(x,y, z, [x_deg, y_deg, z_deg]))

Example

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

# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])

# Display the arrays
print("Array1...
",x) print("
Array2...
",y) print("
Array3...
",z) # Display the datatype print("
Array1 datatype...
",x.dtype) print("
Array2 datatype...
",y.dtype) print("
Array3 datatype...
",z.dtype) # Check the Dimensions print("
Dimensions of Array1...
",x.ndim) print("
Dimensions of Array2...
",y.ndim) print("
Dimensions of Array3...
",z.ndim) # Check the Shape print("
Shape of Array1...
",x.shape) print("
Shape of Array2...
",y.shape) print("
Shape of Array3...
",z.shape) # To generate a pseudo Vandermonde matrix of given degree and x, y, z sample points, use the polynomial.polyvander3d() in Python Numpy x_deg, y_deg, z_deg = 2, 3, 4 print("
Result...
",polyvander3d(x,y, z, [x_deg, y_deg, z_deg]))

Output

Array1...
[1 2]

Array2...
[3 4]

Array3...
[5 6]

Array1 datatype...
int64

Array2 datatype...
int64

Array3 datatype...
int64

Dimensions of Array1...
1

Dimensions of Array2...
1

Dimensions of Array3...
1

Shape of Array1...
(2,)

Shape of Array2...
(2,)

Shape of Array3...
(2,)

Result...
[[1.00000e+00 5.00000e+00 2.50000e+01 1.25000e+02 6.25000e+02 3.00000e+00
1.50000e+01 7.50000e+01 3.75000e+02 1.87500e+03 9.00000e+00 4.50000e+01
2.25000e+02 1.12500e+03 5.62500e+03 2.70000e+01 1.35000e+02 6.75000e+02
3.37500e+03 1.68750e+04 1.00000e+00 5.00000e+00 2.50000e+01 1.25000e+02
6.25000e+02 3.00000e+00 1.50000e+01 7.50000e+01 3.75000e+02 1.87500e+03
9.00000e+00 4.50000e+01 2.25000e+02 1.12500e+03 5.62500e+03 2.70000e+01
1.35000e+02 6.75000e+02 3.37500e+03 1.68750e+04 1.00000e+00 5.00000e+00
2.50000e+01 1.25000e+02 6.25000e+02 3.00000e+00 1.50000e+01 7.50000e+01
3.75000e+02 1.87500e+03 9.00000e+00 4.50000e+01 2.25000e+02 1.12500e+03
5.62500e+03 2.70000e+01 1.35000e+02 6.75000e+02 3.37500e+03 1.68750e+04]
[1.00000e+00 6.00000e+00 3.60000e+01 2.16000e+02 1.29600e+03 4.00000e+00
2.40000e+01 1.44000e+02 8.64000e+02 5.18400e+03 1.60000e+01 9.60000e+01
5.76000e+02 3.45600e+03 2.07360e+04 6.40000e+01 3.84000e+02 2.30400e+03
1.38240e+04 8.29440e+04 2.00000e+00 1.20000e+01 7.20000e+01 4.32000e+02
2.59200e+03 8.00000e+00 4.80000e+01 2.88000e+02 1.72800e+03 1.03680e+04
3.20000e+01 1.92000e+02 1.15200e+03 6.91200e+03 4.14720e+04 1.28000e+02
7.68000e+02 4.60800e+03 2.76480e+04 1.65888e+05 4.00000e+00 2.40000e+01
1.44000e+02 8.64000e+02 5.18400e+03 1.60000e+01 9.60000e+01 5.76000e+02
3.45600e+03 2.07360e+04 6.40000e+01 3.84000e+02 2.30400e+03 1.38240e+04
8.29440e+04 2.56000e+02 1.53600e+03 9.21600e+03 5.52960e+04 3.31776e+05]]
raja
Updated on 28-Feb-2022 11:00:02

Advertisements