在Python中对多维数组中的点x进行Legendre级数评估

在Python中对多维数组中的点x进行Legendre级数评估

在这篇文章中,我们将介绍如何使用NumPy在Python中用一个多维系数数组来评估X点的Legendre数列。

示例:

输入:

[[1 2 3 4 5]

 [3 4 2 6 7]] at points [4,1]

输出:

[[13.4.]

[18. 6.]

[11. 5.]

[28. 10.]

[33. 12.]]

解释:一个多维的系数阵列。

legendre.legval 方法

在python中,Legendre模块提供了许多函数,如legval,用于对Legendre数列进行算术和微积分操作。它是Legendre类所提供的函数之一。 该方法用于生成 Legendre 数列,该方法在 python 的 Legendre 模块中可用,它返回一个多维系数数组,下面是 legval 方法的语法。

语法 : legendre.legval(x, c, tensor)。

参数:

x:一个列表或元组
c:一个有序的系数数组
tensor:布尔值,可选

返回:新数组。

示例 1:

在这个例子中,我们正在创建一个有5个元素的多维NumPy数组的系数,并显示该数组的形状和尺寸。之后,我们在[4,1]点上对Legendre数列进行评估。

# import the numpy module
import numpy
  
# import legendre
from numpy.polynomial import legendre
  
# create array of coefficients with 5 elements each
coefficients_data = numpy.array([[1, 2, 3, 4, 5], 
                                 [3, 4, 2, 6, 7]])
  
# Display the coefficients
print(coefficients_data)
  
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
  
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
  
# Evaluate a legendre series at points - [4,1]
print("\nmultidimensional legendre series",
      legendre.legval([4, 1], coefficients_data))

输出:

[[1 2 3 4 5]
 [3 4 2 6 7]]

Shape of an array: (2, 5)
Dimension: 2

multidimensional legendre series [[13.  4.]
 [18.  6.]
 [11.  5.]
 [28. 10.]
 [33. 12.]]

示例 2:

在这个例子中,我们正在创建一个有3个元素的多维NumPy数组的系数,并显示该数组的形状和尺寸。之后,我们在[[1,3,4,5],[3,2,6,7]]点上对Legendre数列进行评估。

# import the numpy module
import numpy
  
# import legendre
from numpy.polynomial import legendre 
  
# create array of coefficients with 2 elements each
coefficients_data = numpy.array([6,4,7])
  
# Display the coefficients
print(coefficients_data)
  
# get the shape
print(f"\nShape of an array: {coefficients_data.shape}")
  
# get the dimensions
print(f"Dimension: {coefficients_data.ndim}")
  
h = [[1,3,4,5],[3,2,6,7]]
  
# Evaluate a legendre series at points - [6,4]
print("\nmultidimensional legendre series",
      legendre.legval(coefficients_data,h))

输出:

[6 4 7]

Shape of an array: (3,)
Dimension: 1

multidimensional legendre series [[19. 13. 22.]
 [15. 11. 17.]
 [40. 28. 46.]
 [47. 33. 54.]]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Numpy 多项式