在Python中对一个Laguerre系列的元组点x进行求值

在Python中对一个Laguerre系列的元组点x进行求值

要在点x处对Laguerre系列进行求值,可以使用Python Numpy中的polynomial.laguerre.lagval()方法。第一个参数是x。如果x是一个列表或元组,则会转换为ndarray,否则保持不变并被视为标量。无论哪种情况,x或其元素都必须支持自身和c元素的加法和乘法运算。

第二个参数C是一个按照系数为n的项的顺序排列的系数数组。如果c是多维数组,剩下的索引用于列举多个多项式。在二维情况下,可以将系数视为按列排列在c中。

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

步骤

首先,导入所需的库 –

import numpy as np
from numpy.polynomial import laguerre as L

创建一个系数数组 −

c = np.array([1, 2, 3])

显示数组 –

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是一个元组−

x = (5, 10, 15)

Python Numpy中,要在点x处评估Laguerre系列,请使用polynomial.laguerre.lagval()方法。

print("\nResult...\n",L.lagval(x,c))

示例

import numpy as np
from numpy.polynomial import laguerre as L

# Create an array of coefficients
c = np.array([1, 2, 3])

# 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)

# Here, x is a tuple
x = (5, 10, 15)

# To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python Numpy
print("\nResult...\n",L.lagval(x,c))

输出

Our Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result...
   [ 3.5 76. 223.5]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程