在Python中生成切比雪夫多項式和x、y、z樣本點的偽範德蒙德矩陣
要生成切比雪夫多項式和x、y、z樣本點的偽範德蒙德矩陣,可以使用Python NumPy中的`chebyshev.chebvander()`。此方法返回度數為deg且樣本點為(x, y, z)的偽範德蒙德矩陣。
引數x、y、z是點座標陣列,形狀相同。資料型別將轉換為float64或complex128,具體取決於是否有任何元素是複數。標量將轉換為一維陣列。引數deg是最大度數列表,格式為[x_deg, y_deg, z_deg]。
步驟
首先,匯入所需的庫:
import numpy as np from numpy.polynomial import chebyshev as C
使用numpy.array()方法建立形狀相同的點座標陣列:
x = np.array([1, 2]) y = np.array([3, 4]) z = np.array([5, 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樣本點的偽範德蒙德矩陣,請在Python中使用`chebyshev.chebvander()`:
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))示例
import numpy as np
from numpy.polynomial import chebyshev as C
# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 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 Chebyshev polynomial and x, y, z sample points, use the chebyshev.chebvander() in Python Numpy
# The method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z).
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))輸出
Array1... [1 2] Array2... [3 4] Array3... [5 6] Array1 datatype... int64 Array2 datatype... int64 Array3 datatype... int64 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.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03 3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04 1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04 9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05 1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03 3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04 1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04 9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05 1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03 3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04 1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04 9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05] [1.0000000e+00 6.0000000e+00 7.1000000e+01 8.4600000e+02 1.0081000e+04 4.0000000e+00 2.4000000e+01 2.8400000e+02 3.3840000e+03 4.0324000e+04 3.1000000e+01 1.8600000e+02 2.2010000e+03 2.6226000e+04 3.1251100e+05 2.4400000e+02 1.4640000e+03 1.7324000e+04 2.0642400e+05 2.4597640e+06 2.0000000e+00 1.2000000e+01 1.4200000e+02 1.6920000e+03 2.0162000e+04 8.0000000e+00 4.8000000e+01 5.6800000e+02 6.7680000e+03 8.0648000e+04 6.2000000e+01 3.7200000e+02 4.4020000e+03 5.2452000e+04 6.2502200e+05 4.8800000e+02 2.9280000e+03 3.4648000e+04 4.1284800e+05 4.9195280e+06 7.0000000e+00 4.2000000e+01 4.9700000e+02 5.9220000e+03 7.0567000e+04 2.8000000e+01 1.6800000e+02 1.9880000e+03 2.3688000e+04 2.8226800e+05 2.1700000e+02 1.3020000e+03 1.5407000e+04 1.8358200e+05 2.1875770e+06 1.7080000e+03 1.0248000e+04 1.2126800e+05 1.4449680e+06 1.7218348e+07]]
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP