在Python中使用多维系数数组计算Laguerre级数的点x

在Python中使用多维系数数组计算Laguerre级数的点x

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

第二个参数C是一个系数数组,按照这样的顺序排列,每个阶数n的系数包含在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,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)

要在点x处计算Laguerre级数,请使用Python的polynomial.laguerre.lagval()方法
Numpy −

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

示例

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

# Create a multidimensional array of coefficients
c = np.array([[1,2],[3,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))

输出

Our Array...
   [[1 2]
   [3 4]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

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

Result...
   [[ 1. -2.]
   [ 2. -2.]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程