要在点 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.]