在Python中生成拉盖尔多项式和x、y、z浮点数组点的伪范德蒙矩阵
为了生成拉盖尔多项式和x、y、z样本点的伪范德蒙矩阵,在Python的Numpy中使用laguerre.lagvander3d()方法。 参数x、y、z返回一个点的数组。根据元素是否为复数,数据类型转换为float64或complex128。如果x是标量, 它将转换为一个一维数组。参数deg是形式为[x_deg, y_deg, z_deg]的最大度数的列表。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import laguerre as L
创建具有相同形状的点坐标数组,使用numpy.array()方法−
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.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)
使用Python的laguerre.lagvander3d()函数,可以生成带有x、y、z样本点的Laguerre多项式的伪Vandermonde矩阵。
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))
示例
import numpy as np
from numpy.polynomial import laguerre 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 Laguerre polynomial with x, y, z sample points, use the laguerre.lagvander3d() in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))
输出
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. -4.3 4.445 2.42216667 -2.30432917
-2.7 11.61 -12.0015 -6.53985 6.22168875
0.445 -1.9135 1.978025 1.07786417 -1.02542648
1.99283333 -8.56918333 8.85814417 4.82697447 -4.59214397
-0.5 2.15 -2.2225 -1.21108333 1.15216458
1.35 -5.805 6.00075 3.269925 -3.11084437
-0.2225 0.95675 -0.9890125 -0.53893208 0.51271324
-0.99641667 4.28459167 -4.42907208 -2.41348724 2.29607199
-0.875 3.7625 -3.889375 -2.11939583 2.01628802
2.3625 -10.15875 10.5013125 5.72236875 -5.44397766
-0.389375 1.6743125 -1.73077188 -0.94313115 0.89724817
-1.74372917 7.49803542 -7.75087615 -4.22360266 4.01812598]
[ 1. -5.6 9.58 -1.376 -7.3226
-3.4 19.04 -32.572 4.6784 24.89684
1.88 -10.528 18.0104 -2.58688 -13.766488
2.64266667 -14.79893333 25.31674667 -3.63630933 -19.35119093
-1.3 7.28 -12.454 1.7888 9.51938
4.42 -24.752 42.3436 -6.08192 -32.365892
-2.444 13.6864 -23.41352 3.362944 17.8964344
-3.43546667 19.23861333 -32.91177067 4.72720213 25.15654821
-0.955 5.348 -9.1489 1.31408 6.993083
3.247 -18.1832 31.10626 -4.467872 -23.7764822
-1.7954 10.05424 -17.199932 2.4704704 13.14699604
-2.52374667 14.13298133 -24.17749307 3.47267541 18.48038734]]