用给定复数根的 Python 生成勒让德级数
pythonnumpyserver side programmingprogramming更新于 2024/7/8 5:00:17
要生成勒让德级数,请使用 Python 中的 polynomial.legendre.legfromroots() 方法。该方法返回一个一维系数数组。如果所有根都是实数,则 out 是实数数组;如果部分根是复数,则即使结果中的所有系数都是实数,out 也是复数。参数 roots 是包含根的序列。
步骤
首先,导入所需的库 −
from numpy.polynomial import legendre as L
用 Python 中的 polynomial.legendre.legfromroots() 方法生成勒让德级数 −
j = complex(0,1)
print("结果...\n",L.legfromroots((-j, j)))
获取数据类型 −
print("\n类型...\n",L.legfromroots((-j, j)).dtype)
获取形状 −
print("\n形状...\n",L.legfromroots((-j, j)).shape)
示例
from numpy.polynomial import legendre as L
# 要生成勒让德级数,请使用 Python 中的 polynomial.legendre.legfromroots() 方法
j = complex(0,1)
print("结果...\n",L.legfromroots((-j, j)))
# 获取数据类型
print("\n类型...\n",L.legfromroots((-j, j)).dtype)
# 获取形状
print("\n形状...\n",L.legfromroots((-j, j)).shape)
输出
结果... [1.33333333+0.j 0. +0.j 0.66666667+0.j] 类型... complex128 形状... (3,)
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

