在Python中生成勒讓德多項式的偽範德蒙德矩陣和x、y、z點陣
要生成具有x、y、z取樣點的勒讓德多項式的偽範德蒙德矩陣,請在Python NumPy中使用legendre.legvander3d()方法。返回度數為deg且取樣點為(x, y, z)的偽範德蒙德矩陣。
引數x、y、z是點座標陣列,形狀相同。資料型別將根據元素是否為複數轉換為float64或complex128。標量將轉換為一維陣列。引數deg是最大度數列表,格式為[x_deg, y_deg, z_deg]。
步驟
首先,匯入所需的庫:
import numpy as np from numpy.polynomial import legendre as L
使用numpy.array()方法建立形狀相同的點座標陣列:
x = np.array([1, 2]) y = np.array([3, 4]) z = np.array([5, 6])
顯示陣列:
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)顯示資料型別:
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)檢查兩個陣列的維度:
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)檢查兩個陣列的形狀:
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)要生成具有x、y、z取樣點的勒讓德多項式的偽範德蒙德矩陣,請在Python中使用legendre.legvander3d()方法:
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))示例
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, 2])
y = np.array([3, 4])
z = np.array([5, 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]))輸出
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.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02
2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02
9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01
4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01
3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05
1.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02
2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02
9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01
4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01
3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05
1.00000000e+00 5.00000000e+00 3.70000000e+01 3.05000000e+02
2.64100000e+03 3.00000000e+00 1.50000000e+01 1.11000000e+02
9.15000000e+02 7.92300000e+03 1.30000000e+01 6.50000000e+01
4.81000000e+02 3.96500000e+03 3.43330000e+04 6.30000000e+01
3.15000000e+02 2.33100000e+03 1.92150000e+04 1.66383000e+05]
[1.00000000e+00 6.00000000e+00 5.35000000e+01 5.31000000e+02
5.53537500e+03 4.00000000e+00 2.40000000e+01 2.14000000e+02
2.12400000e+03 2.21415000e+04 2.35000000e+01 1.41000000e+02
1.25725000e+03 1.24785000e+04 1.30081312e+05 1.54000000e+02
9.24000000e+02 8.23900000e+03 8.17740000e+04 8.52447750e+05
2.00000000e+00 1.20000000e+01 1.07000000e+02 1.06200000e+03
1.10707500e+04 8.00000000e+00 4.80000000e+01 4.28000000e+02
4.24800000e+03 4.42830000e+04 4.70000000e+01 2.82000000e+02
2.51450000e+03 2.49570000e+04 2.60162625e+05 3.08000000e+02
1.84800000e+03 1.64780000e+04 1.63548000e+05 1.70489550e+06
5.50000000e+00 3.30000000e+01 2.94250000e+02 2.92050000e+03
3.04445625e+04 2.20000000e+01 1.32000000e+02 1.17700000e+03
1.16820000e+04 1.21778250e+05 1.29250000e+02 7.75500000e+02
6.91487500e+03 6.86317500e+04 7.15447219e+05 8.47000000e+02
5.08200000e+03 4.53145000e+04 4.49757000e+05 4.68846262e+06]]
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP