在Python中计算Laguerre级数在点x处的值及系数数组的形状,对于x的每个维度,数组都得扩展

在Python中计算Laguerre级数在点x处的值及系数数组的形状,对于x的每个维度,数组都得扩展

要在点x处计算Laguerre级数,请使用Python中Numpy库的polynomial.laguerre.lagval()方法。第一个参数是x。如果x是一个列表或元组,它将被转换为ndarray,否则它将保持不变并被视为标量。无论哪种情况,x或其元素都必须支持与自身以及c的元素之间的加法和乘法。

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

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

步骤

首先,导入所需的库 –

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

创建一个多维数组的系数 –

c = np.arange(8).reshape(2,4)

展示数组 –

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中的polynomial.laguerre.lagval()方法来评估Laguerre系列在点x处的值。

print("\nResult...\n",L.lagval([1,2],c,tensor = True))

示例

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

# Create a multidimensional array of coefficients
c = np.arange(8).reshape(2,4)

# 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 evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python Numpy
print("\nResult...\n",L.lagval([1,2],c,tensor = True))

输出

Our Array...
   [[0 1 2 3]
   [4 5 6 7]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 4)

Result...
   [[ 0. -4.]
   [ 1. -4.]
   [ 2. -4.]
   [ 3. -4.]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程