在 Python 中使用 1D 系数数组评估点 (x, y) 处的 2D Legendre 系列

阅读 137 收藏 0 点赞 0 评论 0

要在点 x、y 处计算 2D Legendre 系列,请使用d()Python Numpy 中的 polynomial.legendre.legval2 方法。该方法返回二维勒让德级数在点处的值,这些点由来自 x 和 y 的对应值对形成。

第一个参数是 x, y。二维序列在点 (x, y) 处计算,其中 x 和 y 必须具有相同的形状。如果 x 或 y 是列表或元组,则首先将其转换为 ndarray,否则保持不变,如果它不是 ndarray,则将其视为标量。

第二个参数是c。排序的系数数组,使得多度 i,j 项的系数包含在 c[i,j] 中。如果 c 的维度大于两个,则其余索引会枚举多组系数。

脚步

首先,导入所需的库 -

import numpy as np
fromnumpy.polynomialimport 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)

要在点 x、y 处评估 2D Legendre 系列,请使用d()Python Numpy 中的 polynomial.legendre.legval2 方法 -

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

示例

import numpy as np
fromnumpy.polynomialimport 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)

#要在点 x、y 处计算 2D Legendre 系列,请使用 Python Numpy 中的 polynomial.legendre.legval2d() 方法
print("\nResult...\n",L.legval2d([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.]

评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号