在 Python 中生成 Chebyshev 多项式的伪范德蒙矩阵
pythonnumpyserver side programmingprogramming
要生成 Chebyshev 多项式的伪范德蒙矩阵,请使用 Python Numpy 中的 chebyshev.chebvander()。该方法返回度数 deg 和样本点 (x, y) 的伪范德蒙矩阵。
参数 x、y 是点坐标的数组,所有点坐标的形状相同。dtype 将转换为 float64 或 complex128,具体取决于是否有任何元素是复数。标量将转换为一维数组。参数 deg 是 [x_deg, y_deg] 形式的最大度数列表。
步骤
首先,导入所需的库 −
import numpy as np from numpy.polynomial import chebyshev as C
使用 numpy.array() 方法 − 创建点坐标数组,所有数组的形状相同
x = np.array([1, 2]) y = np.array([3, 4])
显示数组 −
print("Array1...\n",x) print("\nArray2...\n",y)
显示数据类型 −
print("\nArray1 datatype...\n",x.dtype) print("\nArray2 datatype...\n",y.dtype)
检查两个数组的维度 −
print("\nDimensions of Array1...\n",x.ndim) print("\nDimensions of Array2...\n",y.ndim)
检查两个数组的形状 −
print("\nShape of Array1...\n",x.shape) print("\nShape of Array2...\n",y.shape)
要生成切比雪夫多项式的伪范德蒙矩阵,请使用 Python 中的 chebyshev.chebvander() −
x_deg, y_deg = 2, 3 print("\n结果...\n",C.chebvander2d(x,y, [x_deg, y_deg]))
示例
import numpy as np from numpy.polynomial import chebyshev as C # 创建数组点坐标,所有点坐标均使用 numpy.array() 方法具有相同的形状 x = np.array([1, 2]) y = np.array([3, 4]) # 显示数组 print("Array1...\n",x) print("\nArray2...\n",y) # 显示数据类型 print("\nArray1 datatype...\n",x.dtype) print("\nArray2 datatype...\n",y.dtype) # 检查两个数组的维度 print("\nDimensions of Array1...\n",x.ndim) print("\nDimensions of Array2...\n",y.ndim) # 检查两个数组的形状 print("\nShape of Array1...\n",x.shape) print("\nShape of Array2...\n",y.shape) # 要生成切比雪夫多项式的伪范德蒙矩阵,请使用 Python Numpy 中的 chebyshev.chebvander() x_deg, y_deg = 2, 3 print("\n结果...\n",C.chebvander2d(x,y, [x_deg, y_deg]))
输出
Array1... [1 2] Array2... [3 4] Array1 datatype... int64 Array2 datatype... int64 Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (2,) Shape of Array2... (2,) 结果... [[1.000e+00 3.000e+00 1.700e+01 9.900e+01 1.000e+00 3.000e+00 1.700e+01 9.900e+01 1.000e+00 3.000e+00 1.700e+01 9.900e+01] [1.000e+00 4.000e+00 3.100e+01 2.440e+02 2.000e+00 8.000e+00 6.200e+01 4.880e+02 7.000e+00 2.800e+01 2.170e+02 1.708e+03]]