使用 Python 生成具有给定根的切比雪夫级数
要通过指定根生成切比雪夫级数,请在 Python Numpy 中使用 chebyshev.chebfromroots() 方法。该方法返回系数的 1-D 数组。如果所有根都是实数,则 out 是实数数组,如果一些根是复数,则 out 是复数,即使结果中所有的系数都是实数也是如此。参数 roots 是包含根的序列。
步骤
首先,导入必需的库 -
import numpy as np from numpy.polynomial import chebyshev as C
要通过指定根生成切比雪夫级数,请在 Python Numpy 中使用 chebyshev.chebfromroots() 方法 -
print("Result...\n",C.chebfromroots((-1,0,1)))获取数据类型 -
print("\nType...\n",C.chebfromroots((-1,0,1)).dtype)获取形状 -
print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)
示例
import numpy as np
from numpy.polynomial import chebyshev as C
# To generate a Chebyshev series with given roots, use the chebyshev.chebfromroots() method in Python Numpy.
print("Result...\n",C.chebfromroots((-1,0,1)))
# Get the datatype
print("\nType...\n",C.chebfromroots((-1,0,1)).dtype)
# Get the shape
print("\nShape...\n",C.chebfromroots((-1,0,1)).shape)输出
Result... [ 0. -0.25 0. 0.25] Type... float64 Shape... (4,)
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP