# Generate a Pseudo Vandermonde matrix of the Legendre polynomial and x, y, z floating array of points in Python

PythonNumpyServer Side ProgrammingProgramming

To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python Numpy. Returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z).

The parameters, x, y ,z are 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 a list of maximum degrees of the form [x_deg, y_deg, z_deg].

## Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import legendre as L

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

x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

Display the arrays −

print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

Display the datatype −

print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

Check the Dimensions of both the arrays −

print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

Check the Shape of both the arrays −

print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python −

x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))

## Example

import numpy as np
from numpy.polynomial import legendre as L

# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

# Display the arrays
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

# Display the datatype
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

# To generate a pseudo Vandermonde matrix of the Legendre polynomial with x, y, z sample points, use the legendre.legvander3d() method in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))

## Output

Array1...
[1.5 2.3]

Array2...
[3.7 4.4]

Array3...
[5.3 6.6]

Array1 datatype...
float64

Array2 datatype...
float64

Array3 datatype...
float64

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.00000000e+00 5.30000000e+00 4.16350000e+01 3.64242500e+02
3.34712294e+03 3.70000000e+00 1.96100000e+01 1.54049500e+02
1.34769725e+03 1.23843549e+04 2.00350000e+01 1.06185500e+02
8.34157225e+02 7.29759849e+03 6.70596081e+04 1.21082500e+02
6.41737250e+02 5.04126989e+03 4.41033925e+04 4.05278013e+05
1.50000000e+00 7.95000000e+00 6.24525000e+01 5.46363750e+02
5.02068441e+03 5.55000000e+00 2.94150000e+01 2.31074250e+02
2.02154588e+03 1.85765323e+04 3.00525000e+01 1.59278250e+02
1.25123584e+03 1.09463977e+04 1.00589412e+05 1.81623750e+02
9.62605875e+02 7.56190483e+03 6.61550888e+04 6.07917020e+05
2.87500000e+00 1.52375000e+01 1.19700625e+02 1.04719719e+03
9.62297845e+03 1.06375000e+01 5.63787500e+01 4.42892313e+02
3.87462959e+03 3.56050202e+04 5.76006250e+01 3.05283313e+02
2.39820202e+03 2.09805957e+04 1.92796373e+05 3.48112188e+02
1.84499459e+03 1.44936509e+04 1.26797253e+05 1.16517429e+06]
[1.00000000e+00 6.60000000e+00 6.48400000e+01 7.08840000e+02
8.13847200e+03 4.40000000e+00 2.90400000e+01 2.85296000e+02
3.11889600e+03 3.58092768e+04 2.85400000e+01 1.88364000e+02
1.85053360e+03 2.02302936e+04 2.32271991e+05 2.06360000e+02
1.36197600e+03 1.33803824e+04 1.46276222e+05 1.67945508e+06
2.30000000e+00 1.51800000e+01 1.49132000e+02 1.63033200e+03
1.87184856e+04 1.01200000e+01 6.67920000e+01 6.56180800e+02
7.17346080e+03 8.23613366e+04 6.56420000e+01 4.33237200e+02
4.25622728e+03 4.65296753e+04 5.34225579e+05 4.74628000e+02
3.13254480e+03 3.07748795e+04 3.36435312e+05 3.86274669e+06
7.43500000e+00 4.90710000e+01 4.82085400e+02 5.27022540e+03
6.05095393e+04 3.27140000e+01 2.15912400e+02 2.12117576e+03
2.31889918e+04 2.66241973e+05 2.12194900e+02 1.40048634e+03
1.37587173e+04 1.50412233e+05 1.72694225e+06 1.53428660e+03
1.01262916e+04 9.94831431e+04 1.08756371e+06 1.24867485e+07]]