在 Python 中生成 Chebyshev 多项式的 Vandermonde 矩阵
pythonnumpyserver side programmingprogramming更新于 2024/5/13 3:24:17
要生成 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, 1, -1, 2])
显示数组 −
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, 1, -1, 2])
# 显示数组
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 1 -1 2] 我们的数组的维度... 1 我们的数组对象的数据类型... int64 我们的数组对象的形状... (4,) 结果... [[ 1. 0. -1.] [ 1. 1. 1.] [ 1. -1. 1.] [ 1. 2. 7.]]
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

