在 Python 中生成 Hermite 多项式的伪 Vandermonde 矩阵和 x、y、z 点的复数数组
pythonnumpyserver side programmingprogramming
要生成 Hermite 多项式的伪 Vandermonde 矩阵和 x、y、z 样本点,请使用 Python Numpy 中的 hermite.hermvander3d()。该方法返回伪 Vandermonde 矩阵。参数 x、y、z 是点坐标的数组,所有数组的形状都相同。dtype 将转换为 float64 或 complex128,具体取决于是否有任何元素是复数。标量将转换为一维数组。参数 deg 是 [x_deg, y_deg, z_deg] 形式的最大度数列表。
步骤
首先,导入所需的库 −
numpy as np from numpy.polynomial import hermite as H
使用 numpy.array() 方法 − 创建点坐标数组,所有数组的形状相同
x = np.array([-2.+2.j, -1.+2.j]) y = np.array([0.+2.j, 1.+2.j]) z = np.array([2.+2.j, 3. + 3.j])
显示数组−
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)
要生成 Hermite 多项式和 x、y、z 样本点的伪 Vandermonde 矩阵,请使用 hermite.hermvander3d() −
x_deg, y_deg, z_deg = 2, 3, 4 print("\n结果...\n",H.hermvander3d(x,y,z, [x_deg, y_deg, z_deg]))
示例
import numpy as np from numpy.polynomial import hermite as H # 使用 numpy.array() 方法创建点坐标数组,所有数组的形状相同 x = np.array([-2.+2.j, -1.+2.j]) y = np.array([0.+2.j, 1.+2.j]) z = np.array([2.+2.j, 3. + 3.j]) # 显示数组 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) # 要生成 Hermite 多项式和 x、y、z 样本点的伪 Vandermonde 矩阵,请使用 Python Numpy 中的 hermite.hermvander3d() x_deg, y_deg, z_deg = 2, 3, 4 print("\n结果...\n",H.hermvander3d(x,y,z, [x_deg, y_deg, z_deg]))
输出
Array1... [-2.+2.j -1.+2.j] Array2... [0.+2.j 1.+2.j] Array3... [2.+2.j 3.+3.j] Array1 datatype... complex128 Array2 datatype... complex128 Array3 datatype... complex128 Dimensions of Array1... 1 Dimensions of Array2... 1 Dimensions of Array3... 1 Shape of Array1... (2,) Shape of Array2... (2,) Shape of Array3... (2,) 结果... [[ 1.000000e+00+0.000000e+00j 4.000000e+00+4.000000e+00j -2.000000e+00+3.200000e+01j -1.520000e+02+1.040000e+02j -1.012000e+03-3.840000e+02j 0.000000e+00+4.000000e+00j -1.600000e+01+1.600000e+01j -1.280000e+02-8.000000e+00j -4.160000e+02-6.080000e+02j 1.536000e+03-4.048000e+03j -1.800000e+01+0.000000e+00j -7.200000e+01-7.200000e+01j 3.600000e+01-5.760000e+02j 2.736000e+03-1.872000e+03j 1.821600e+04+6.912000e+03j 0.000000e+00-8.800000e+01j 3.520000e+02-3.520000e+02j 2.816000e+03+1.760000e+02j 9.152000e+03+1.337600e+04j -3.379200e+04+8.905600e+04j -4.000000e+00+4.000000e+00j -3.200000e+01+0.000000e+00j -1.200000e+02-1.360000e+02j 1.920000e+02-1.024000e+03j 5.584000e+03-2.512000e+03j -1.600000e+01-1.600000e+01j 0.000000e+00-1.280000e+02j 5.440000e+02-4.800000e+02j 4.096000e+03+7.680000e+02j 1.004800e+04+2.233600e+04j 7.200000e+01-7.200000e+01j 5.760000e+02+0.000000e+00j 2.160000e+03+2.448000e+03j -3.456000e+03+1.843200e+04j -1.005120e+05+4.521600e+04j 3.520000e+02+3.520000e+02j 0.000000e+00+2.816000e+03j -1.196800e+04+1.056000e+04j -9.011200e+04-1.689600e+04j -2.210560e+05-4.913920e+05j -2.000000e+00-3.200000e+01j 1.200000e+02-1.360000e+02j 1.028000e+03+0.000000e+00j 3.632000e+03+4.656000e+03j -1.026400e+04+3.315200e+04j 1.280000e+02-8.000000e+00j 5.440000e+02+4.800000e+02j 0.000000e+00+4.112000e+03j -1.862400e+04+1.452800e+04j -1.326080e+05-4.105600e+04j 3.600000e+01+5.760000e+02j -2.160000e+03+2.448000e+03j -1.850400e+04+0.000000e+00j -6.537600e+04-8.380800e+04j 1.847520e+05-5.967360e+05j -2.816000e+03+1.760000e+02j -1.196800e+04-1.056000e+04j 0.000000e+00-9.046400e+04j 4.097280e+05-3.196160e+05j 2.917376e+06+9.032320e+05j] [ 1.000000e+00+0.000000e+00j 6.000000e+00+6.000000e+00j -2.000000e+00+7.200000e+01j -4.680000e+02+3.960000e+02j -5.172000e+03-8.640000e+02j 2.000000e+00+4.000000e+00j -1.200000e+01+3.600000e+01j -2.920000e+02+1.360000e+02j -2.520000e+03-1.080000e+03j -6.888000e+03-2.241600e+04j -1.400000e+01+1.600000e+01j -1.800000e+02+1.200000e+01j -1.124000e+03-1.040000e+03j 2.160000e+02-1.303200e+04j 8.623200e+04-7.065600e+04j -1.000000e+02-4.000000e+01j -3.600000e+02-8.400000e+02j 3.080000e+03-7.120000e+03j 6.264000e+04-2.088000e+04j 4.826400e+05+2.932800e+05j -2.000000e+00+4.000000e+00j -3.600000e+01+1.200000e+01j -2.840000e+02-1.520000e+02j -6.480000e+02-2.664000e+03j 1.380000e+04-1.896000e+04j -2.000000e+01+0.000000e+00j -1.200000e+02-1.200000e+02j 4.000000e+01-1.440000e+03j 9.360000e+03-7.920000e+03j 1.034400e+05+1.728000e+04j -3.600000e+01-8.800000e+01j 3.120000e+02-7.440000e+02j 6.408000e+03-2.416000e+03j 5.169600e+04+2.692800e+04j 1.101600e+05+4.862400e+05j 3.600000e+02-3.200000e+02j 4.080000e+03+2.400000e+02j 2.232000e+04+2.656000e+04j -4.176000e+04+2.923200e+05j -2.138400e+06+1.344000e+06j -1.400000e+01-1.600000e+01j 1.200000e+01-1.800000e+02j 1.180000e+03-9.760000e+02j 1.288800e+04+1.944000e+03j 5.858400e+04+9.484800e+04j 3.600000e+01-8.800000e+01j 7.440000e+02-3.120000e+02j 6.264000e+03+2.768000e+03j 1.800000e+04+5.544000e+04j -2.622240e+05+4.240320e+05j 4.520000e+02+0.000000e+00j 2.712000e+03+2.712000e+03j -9.040000e+02+3.254400e+04j -2.115360e+05+1.789920e+05j -2.337744e+06-3.905280e+05j 7.600000e+02+2.160000e+03j -8.400000e+03+1.752000e+04j -1.570400e+05+5.040000e+04j -1.211040e+06-7.099200e+05j -2.064480e+06-1.182816e+07j]]