在Python中使用系数为一维数组的Legendre多项式系列评估笛卡尔积x和y

在Python中使用系数为一维数组的Legendre多项式系列评估笛卡尔积x和y

要在x和y的笛卡尔积上评估2D Legendre多项式系列,可以使用Python的Numpy库中的polynomial.legendre.leggrid2d()方法。该方法返回笛卡尔积x和y上的二维Chebyshev多项式系列的值。如果系数数组c的维数少于两维,则会在其形状中隐式添加1的维度,使其成为2维。结果的形状将为c.shape[2:] + x.shape + y.shape。

第一个参数是x,y。在笛卡尔积x和y上评估二维系列的点。如果x或y是一个列表或元组,它将首先转换为ndarray,否则将保持不变,并且如果它不是一个ndarray,则将其视为标量。

第二个参数是c。按照多重次数i,j的顺序排列的系数数组,其中i,j的多重次数的系数包含在c[i,j]中。如果c的维数大于两维,则剩余指标将枚举多组系数。

步骤

首先,导入所需的库 –

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

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

c = np.array([3, 5])

显示数组 –

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.legendre.leggrid2d()方法来评估笛卡尔积x和y的二维Legendre级数。该方法返回笛卡尔积x和y上的二维Chebyshev级数的值。

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

示例

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

# Create a 1d array of coefficients
c = np.array([3, 5])

# 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 2D Legendre series on the Cartesian product of x and y, use the polynomial.legendre.leggrid2d() method in Python Numpy
print("\nResult...\n",L.leggrid2d([1,2],[1,2],c))

输出

Our Array...
   [3 5]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [21. 34.]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程