使用 Python 中的浮点数组生成 Chebyshev 多项式的 Vandermonde 矩阵
pythonnumpyserver side programmingprogramming
要生成 Chebyshev 多项式的 Vandermonde 矩阵,请使用 Python Numpy 中的 chebyshev.chebvander()。该方法返回 Vandermonde 矩阵。返回矩阵的形状为 x.shape + (deg + 1,),其中最后一个索引是相应 Chebyshev 多项式的度数。dtype 将与转换后的 x 相同。
参数 a 是点数组。dtype 转换为 float64 或 complex128,具体取决于是否有任何元素是复数。如果 x 是标量,则将其转换为一维数组。参数 deg 是结果矩阵的度数。
步骤
首先,导入所需的库 −
import numpy as np from numpy.polynomial import chebyshev as C
创建一个数组 −
x = np.array([0, 3.5, -1.4, 2.5])
显示数组 −
print("我们的数组...\n",x)
检查维度 −
打印("\n我们的数组的维度...\n",x.ndim)
获取数据类型 −
print("\n我们的数组对象的数据类型...\n",x.dtype)
获取形状 −
print("\n我们的数组对象的形状...\n",x.shape)
要生成切比雪夫多项式的范德蒙矩阵,请使用 Python 中的 chebyshev.chebvander() −
print("\n结果...\n",C.chebvander(x, 2))
示例
import numpy as np from numpy.polynomial import chebyshev as C # 创建数组 x = np.array([0, 3.5, -1.4, 2.5]) # 显示数组 print("我们的数组...\n",x) # 检查维度 打印("\n我们的数组的维度...\n",x.ndim) # 获取数据类型 print("\n我们的数组对象的数据类型...\n",x.dtype) # 获取形状 print("\n我们的数组对象的形状...\n",x.shape) # 要生成切比雪夫多项式的范德蒙矩阵,请使用 Python Numpy 中的 chebyshev.chebvander() print("\n结果...\n",C.chebvander(x, 2))
输出
我们的数组... [ 0. 3.5 -1.4 2.5] 我们的数组的维度... 1 我们的数组对象的数据类型... float64 我们的数组对象的形状... (4,) 结果... [[ 1. 0. -1. ] [ 1. 3.5 23.5 ] [ 1. -1.4 2.92] [ 1. 2.5 11.5 ]]