要在点 x 处计算 Chebyshev 系列,请使用 Python Numpy 中的 chebyshev.chebval(() 方法。第一个参数 x,如果 x 是列表或元组,则将其转换为 ndarray,否则保持不变并进行处理作为标量。在任何一种情况下,x 或其元素都必须支持与自身以及与 c 的元素的加法和乘法。第二个参数 C,一个排序的系数数组,以便 n 次项的系数包含在 c 中[n]. 如果 c 是多维的,则剩余索引枚举多个多项式。在二维情况下,可以认为系数存储在 c 的列中。
第三个参数,张量,如果为True,则系数数组的形状在右边扩展为1,x的每个维度一个。此操作的标量维度为 0。结果是 c 中的每一列系数都针对 x 的每个元素进行评估。如果为 False,则 x 在 c 的列上广播以进行评估。当 c 是多维的时,此关键字很有用。默认值是true。
脚步
首先,导入所需的库 -
import numpy as np fromnumpy.polynomialimport chebyshev as C
创建一个多维系数数组 -
c = np.arange(4).reshape(2,2)
显示数组 -
print("Our Array...\n",c)
检查尺寸 -
print("\nDimensions of our Array...\n",c.ndim)
获取数据类型 -
print("\nDatatype of our Array object...\n",c.dtype)
获得形状 -
print("\nShape of our Array object...\n",c.shape)
要在点 x 处评估 Chebyshev 系列,请使用 chebyshev.chebval(() 方法 -
print("\nResult (chebval)...\n",C.chebval([1,2],c,tensor=True))
示例
import numpy as np fromnumpy.polynomialimport chebyshev as C #创建一个多维系数数组 c = np.arange(4).reshape(2,2) #显示数组 print("Our Array...\n",c) #检查尺寸 print("\nDimensions of our Array...\n",c.ndim) #获取数据类型 print("\nDatatype of our Array object...\n",c.dtype) #获取形状 print("\nShape of our Array object...\n",c.shape) #要在点 x 处计算 Chebyshev 系列,请使用 Python Numpy 中的 chebyshev.chebval(() 方法 print("\nResult (chebval)...\n",C.chebval([1,2],c,tensor=True))输出结果
Our Array... [[0 1] [2 3]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result (chebval)... [[2. 4.] [4. 7.]]