在 Python 中生成 Chebyshev 多项式的伪范德蒙矩阵和 x、y、z 点浮点数组
pythonnumpyserver side programmingprogramming更新于 2024/4/29 10:52:17
要生成 Chebyshev 多项式的伪范德蒙矩阵和 x、y、z 样本点,请使用 Python Numpy 中的 chebyshev.chebvander()。该方法返回度 deg 和样本点 (x、y、z) 的伪范德蒙矩阵。
参数 x、y、z 是点坐标的数组,所有数组的形状都相同。dtype 将转换为 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("\n结果...\n",C.chebvander3d(x,y, z, [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 样本点的伪范德蒙矩阵,请使用 Python Numpy 中的 chebyshev.chebvander()
x_deg, y_deg, z_deg = 2, 3, 4
print("\n结果...\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,) 结果... [[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]]
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

