使用 Python 中的点坐标浮点数组生成 Chebyshev 多项式的伪范德蒙矩阵
pythonnumpyserver side programmingprogramming更新于 2024/4/29 7:40:17
要生成 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([0.1, 1.4]) y = np.array([1.7, 2.8])
显示数组 −
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([0.1, 1.4])
y = np.array([1.7, 2.8])
# 显示数组
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... [0.1 1.4] Array2... [1.7 2.8] Array1 数据类型... float64 Array2 数据类型... float64 Array1 的维度... 1 Array2 的维度... 1 Array1 的形状... (2,) Array2 的形状... (2,) 结果... [[ 1.0000000e+00 1.7000000e+00 4.7800000e+00 1.4552000e+01 1.0000000e-01 1.7000000e-01 4.7800000e-01 1.4552000e+00 -9.8000000e-01 -1.6660000e+00 -4.6844000e+00 -1.4260960e+01] [ 1.0000000e+00 2.8000000e+00 1.4680000e+01 7.9408000e+01 1.4000000e+00 3.9200000e+00 2.0552000e+01 1.1117120e+02 2.9200000e+00 8.1760000e+00 4.2865600e+01 2.3187136e+02]]
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

