在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]]
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP