在 Python 中去除切比雪夫多项式的尾部小系数
要从切比雪夫多项式中去除尾部小系数,请在 Python Numpy 中使用 chebyshev.chebtrim() 方法。该方法返回一个去除了尾部零的 1 维数组。如果结果级数为空,则返回包含单个零的级数。
“小”表示“绝对值小”,由参数 tol 控制;“尾部”表示最高阶系数,例如,在 [0, 1, 1, 0, 0](表示 0 + x + x**2 + 0*x**3 + 0*x**4)中,第 3 阶和第 4 阶系数都将被“修剪”。参数 c 是一个系数的 1 维数组,按从低阶到高阶排序。参数 tol 是绝对值小于或等于 tol 的尾部元素将被移除。
步骤
首先,导入所需的库 -
import numpy as np from numpy.polynomial import chebyshev as C
使用 numpy.array() 方法创建数组。这是系数的 1 维数组 -
c = np.array([0,5,0, 0,9,0])
显示数组 -
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)要从切比雪夫多项式中去除尾部小系数,请在 Python Numpy 中使用 chebyshev.chebtrim() 方法 -
print("\nResult...\n",C.chebtrim((c)))示例
import numpy as np
from numpy.polynomial import chebyshev as C
# Create an array using the numpy.array() method
# This is the 1-d array of coefficients
c = np.array([0,5,0, 0,9,0])
# 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 remove small trailing coefficients from Chebyshev polynomial, use the chebyshev.chebtrim() method in Python Numpy.
print("\nResult...\n",C.chebtrim((c)))输出
Our Array... [0 5 0 0 9 0] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (6,) Result... [0. 5. 0. 0. 9.]
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP