在 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.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 樣本點,請使用 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.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 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
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.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 5.51800000e+01 5.79608000e+02 6.08866480e+03 3.70000000e+00 1.96100000e+01 2.04166000e+02 2.14454960e+03 2.25280598e+04 2.63800000e+01 1.39814000e+02 1.45564840e+03 1.52900590e+04 1.60618977e+05 1.91512000e+02 1.01501360e+03 1.05676322e+04 1.11001887e+05 1.16605237e+06 1.50000000e+00 7.95000000e+00 8.27700000e+01 8.69412000e+02 9.13299720e+03 5.55000000e+00 2.94150000e+01 3.06249000e+02 3.21682440e+03 3.37920896e+04 3.95700000e+01 2.09721000e+02 2.18347260e+03 2.29350886e+04 2.40928466e+05 2.87268000e+02 1.52252040e+03 1.58514482e+04 1.66502831e+05 1.74907856e+06 3.50000000e+00 1.85500000e+01 1.93130000e+02 2.02862800e+03 2.13103268e+04 1.29500000e+01 6.86350000e+01 7.14581000e+02 7.50592360e+03 7.88482092e+04 9.23300000e+01 4.89349000e+02 5.09476940e+03 5.35152066e+04 5.62166421e+05 6.70292000e+02 3.55254760e+03 3.69867126e+04 3.88506606e+05 4.08118331e+06] [1.00000000e+00 6.60000000e+00 8.61200000e+01 1.13018400e+03 1.48323088e+04 4.40000000e+00 2.90400000e+01 3.78928000e+02 4.97280960e+03 6.52621587e+04 3.77200000e+01 2.48952000e+02 3.24844640e+03 4.26305405e+04 5.59474688e+05 3.27536000e+02 2.16173760e+03 2.82074003e+04 3.70175947e+05 4.85811510e+06 2.30000000e+00 1.51800000e+01 1.98076000e+02 2.59942320e+03 3.41143102e+04 1.01200000e+01 6.67920000e+01 8.71534400e+02 1.14374621e+04 1.50102965e+05 8.67560000e+01 5.72589600e+02 7.47142672e+03 9.80502431e+04 1.28679178e+06 7.53332800e+02 4.97199648e+03 6.48770207e+04 8.51404677e+05 1.11736647e+07 9.58000000e+00 6.32280000e+01 8.25029600e+02 1.08271627e+04 1.42093518e+05 4.21520000e+01 2.78203200e+02 3.63013024e+03 4.76395160e+04 6.25211481e+05 3.61357600e+02 2.38496016e+03 3.11201165e+04 4.08400578e+05 5.35976751e+06 3.13779488e+03 2.07094462e+04 2.70226895e+05 3.54628557e+06 4.65407426e+07]]
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP