在Python中计算多维Chebyshev级数的点x的值

在Python中计算多维Chebyshev级数的点x的值

要在点x处计算Chebyshev级数的值,可以使用Python的NumPy库中的chebyshev.chebval()方法。第一个参数x如果是一个列表或元组,则转换为ndarray,否则保持不变并视为标量。在任何情况下,x或其元素必须支持与自身和c的元素进行加法和乘法运算。第二个参数C是一个按照n次项的系数进行排序的数组,n次项的系数包含在c[n]中。如果c是多维的,其余的索引枚举多个多项式。在二维情况下,可以将系数视为存储在c的列中。

第三个参数tensor,如果为True,则通过在右侧添加一个维度的1来扩展系数数组的形状,对于x的每个维度都添加一个。对于此操作,标量的维度为0。结果是对于c中的每一列系数,都对x的每个元素进行求值。如果为False,则x在求值时在c的列上广播。当c是多维时,这个关键字非常有用,默认值为True。

步骤

首先,导入所需的库-

import numpy as np
from numpy.polynomial import 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
from numpy.polynomial import chebyshev as C

# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To evaluate a Chebyshev series at points x, use thechebyshev.chebval(() method in Python Numpy
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.]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程