在Python中评估Laguerre级数的多维数组点

在Python中评估Laguerre级数的多维数组点

要在多维数组点x上评估Laguerre级数,请使用Python Numpy中的polynomial.laguerre.lagval()方法。第一个参数是x。如果x是列表或元组,则会转换为ndarray,否则将保持不变并被视为标量。在任何情况下,x或其元素必须支持与它们自己和c的元素进行加法和乘法。

第二个参数C是一个按次数n排序的系数数组,其中n次项的系数包含在c[n]中。如果c是多维的,剩余的索引将枚举多个多项式。在二维情况下,系数可以被视为存储在c的列中。

第三个参数tensor,如果为True,则可以将系数数组的形状扩展为在右侧添加的1,每个维度对应一个。对于此操作,标量的维度为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 = np.array([[1,2],[3,4]])

要在多维点数组x上评估Laguerre级数,请使用Python Numpy中的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 2D array
x = np.array([[1,2],[3,4]])

# To evaluate a Laguerre series at multi-dimensional array of 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...
   [[-0.5 -4. ]
   [-4.5 -2. ]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程