在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([-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)
要生成给定阶数和样本点(x, y, z)的范德蒙德矩阵,请使用Python Numpy中的`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([-2.+2.j, -1.+2.j]) y = np.array([0.+2.j, 1.+2.j]) z = np.array([2.+2.j, 3. + 3.j]) # 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... [-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,) Result... [[ 1.000e+00+0.000e+00j 2.000e+00+2.000e+00j 0.000e+00+8.000e+00j -1.600e+01+1.600e+01j -6.400e+01+0.000e+00j 0.000e+00+2.000e+00j -4.000e+00+4.000e+00j -1.600e+01+0.000e+00j -3.200e+01-3.200e+01j -0.000e+00-1.280e+02j -4.000e+00+0.000e+00j -8.000e+00-8.000e+00j -0.000e+00-3.200e+01j 6.400e+01-6.400e+01j 2.560e+02-0.000e+00j 0.000e+00-8.000e+00j 1.600e+01-1.600e+01j 6.400e+01+0.000e+00j 1.280e+02+1.280e+02j 0.000e+00+5.120e+02j -2.000e+00+2.000e+00j -8.000e+00+0.000e+00j -1.600e+01-1.600e+01j 0.000e+00-6.400e+01j 1.280e+02-1.280e+02j -4.000e+00-4.000e+00j 0.000e+00-1.600e+01j 3.200e+01-3.200e+01j 1.280e+02+0.000e+00j 2.560e+02+2.560e+02j 8.000e+00-8.000e+00j 3.200e+01+0.000e+00j 6.400e+01+6.400e+01j 0.000e+00+2.560e+02j -5.120e+02+5.120e+02j 1.600e+01+1.600e+01j 0.000e+00+6.400e+01j -1.280e+02+1.280e+02j -5.120e+02+0.000e+00j -1.024e+03-1.024e+03j 0.000e+00-8.000e+00j 1.600e+01-1.600e+01j 6.400e+01+0.000e+00j 1.280e+02+1.280e+02j 0.000e+00+5.120e+02j 1.600e+01+0.000e+00j 3.200e+01+3.200e+01j 0.000e+00+1.280e+02j -2.560e+02+2.560e+02j -1.024e+03+0.000e+00j 0.000e+00+3.200e+01j -6.400e+01+6.400e+01j -2.560e+02+0.000e+00j -5.120e+02-5.120e+02j -0.000e+00-2.048e+03j -6.400e+01+0.000e+00j -1.280e+02-1.280e+02j -0.000e+00-5.120e+02j 1.024e+03-1.024e+03j 4.096e+03-0.000e+00j] [ 1.000e+00+0.000e+00j 3.000e+00+3.000e+00j 0.000e+00+1.800e+01j -5.400e+01+5.400e+01j -3.240e+02+0.000e+00j 1.000e+00+2.000e+00j -3.000e+00+9.000e+00j -3.600e+01+1.800e+01j -1.620e+02-5.400e+01j -3.240e+02-6.480e+02j -3.000e+00+4.000e+00j -2.100e+01+3.000e+00j -7.200e+01-5.400e+01j -5.400e+01-3.780e+02j 9.720e+02-1.296e+03j -1.100e+01-2.000e+00j -2.700e+01-3.900e+01j 3.600e+01-1.980e+02j 7.020e+02-4.860e+02j 3.564e+03+6.480e+02j -1.000e+00+2.000e+00j -9.000e+00+3.000e+00j -3.600e+01-1.800e+01j -5.400e+01-1.620e+02j 3.240e+02-6.480e+02j -5.000e+00+0.000e+00j -1.500e+01-1.500e+01j -0.000e+00-9.000e+01j 2.700e+02-2.700e+02j 1.620e+03-0.000e+00j -5.000e+00-1.000e+01j 1.500e+01-4.500e+01j 1.800e+02-9.000e+01j 8.100e+02+2.700e+02j 1.620e+03+3.240e+03j 1.500e+01-2.000e+01j 1.050e+02-1.500e+01j 3.600e+02+2.700e+02j 2.700e+02+1.890e+03j -4.860e+03+6.480e+03j -3.000e+00-4.000e+00j 3.000e+00-2.100e+01j 7.200e+01-5.400e+01j 3.780e+02+5.400e+01j 9.720e+02+1.296e+03j 5.000e+00-1.000e+01j 4.500e+01-1.500e+01j 1.800e+02+9.000e+01j 2.700e+02+8.100e+02j -1.620e+03+3.240e+03j 2.500e+01+0.000e+00j 7.500e+01+7.500e+01j 0.000e+00+4.500e+02j -1.350e+03+1.350e+03j -8.100e+03+0.000e+00j 2.500e+01+5.000e+01j -7.500e+01+2.250e+02j -9.000e+02+4.500e+02j -4.050e+03-1.350e+03j -8.100e+03-1.620e+04j]]
广告