在 Python 中生成给定度数和 x、y、z 浮点数组点的伪范德蒙矩阵


要生成给定度数和样本点 (x、y、z) 的范德蒙矩阵,请使用 Python Numpy 中的 polynomial.polyvander3d()。该方法返回度数为 deg 和样本点 (x、y、z) 的伪范德蒙矩阵。参数 x、y、z 是点坐标数组,都具有相同的形状。数据类型将转换为 float64 或 complex128,具体取决于任何元素是否为复数。标量将转换为一维数组。参数 deg 是形式为 [x_deg, y_deg, z_deg] 的最大度数列表。

步骤

首先,导入所需的库 -

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

使用 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)

要生成给定度数和样本点 (x、y、z) 的范德蒙矩阵,请使用 polynomial.polyvander3d() -

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

示例

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.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
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

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

# To generate a Vandermonde matrix of given degree and sample points (x, y, z)., use the polynomial.polyvander3d() in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",polyvander3d(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.00000000e+00 5.30000000e+00 2.80900000e+01 1.48877000e+02
7.89048100e+02 3.70000000e+00 1.96100000e+01 1.03933000e+02
5.50844900e+02 2.91947797e+03 1.36900000e+01 7.25570000e+01
3.84552100e+02 2.03812613e+03 1.08020685e+04 5.06530000e+01
2.68460900e+02 1.42284277e+03 7.54106668e+03 3.99676534e+04
1.50000000e+00 7.95000000e+00 4.21350000e+01 2.23315500e+02
1.18357215e+03 5.55000000e+00 2.94150000e+01 1.55899500e+02
8.26267350e+02 4.37921695e+03 2.05350000e+01 1.08835500e+02
5.76828150e+02 3.05718920e+03 1.62031027e+04 7.59795000e+01
4.02691350e+02 2.13426415e+03 1.13116000e+04 5.99514801e+04
2.25000000e+00 1.19250000e+01 6.32025000e+01 3.34973250e+02
1.77535822e+03 8.32500000e+00 4.41225000e+01 2.33849250e+02
1.23940102e+03 6.56882543e+03 3.08025000e+01 1.63253250e+02
8.65242225e+02 4.58578379e+03 2.43046541e+04 1.13969250e+02
6.04037025e+02 3.20139623e+03 1.69674000e+04 8.99272202e+04]
[1.00000000e+00 6.60000000e+00 4.35600000e+01 2.87496000e+02
1.89747360e+03 4.40000000e+00 2.90400000e+01 1.91664000e+02
1.26498240e+03 8.34888384e+03 1.93600000e+01 1.27776000e+02
8.43321600e+02 5.56592256e+03 3.67350889e+04 8.51840000e+01
5.62214400e+02 3.71061504e+03 2.44900593e+04 1.61634391e+05
2.30000000e+00 1.51800000e+01 1.00188000e+02 6.61240800e+02
4.36418928e+03 1.01200000e+01 6.67920000e+01 4.40827200e+02
2.90945952e+03 1.92024328e+04 4.45280000e+01 2.93884800e+02
1.93963968e+03 1.28016219e+04 8.44907045e+04 1.95923200e+02
1.29309312e+03 8.53441459e+03 5.63271363e+04 3.71759100e+05
5.29000000e+00 3.49140000e+01 2.30432400e+02 1.52085384e+03
1.00376353e+04 2.32760000e+01 1.53621600e+02 1.01390256e+03
6.69175690e+03 4.41655955e+04 1.02414400e+02 6.75935040e+02
4.46117126e+03 2.94437303e+04 1.94328620e+05 4.50623360e+02
2.97411418e+03 1.96291536e+04 1.29552414e+05 8.55045929e+05]]

更新于: 2022-02-28

123 次查看

启动您的 职业生涯

通过完成课程获得认证

开始学习
广告