在 Python 中生成拉盖尔多项式的伪范德蒙矩阵和 x、y、z 浮点数组

pythonnumpyserver side programmingprogramming更新于 2024/6/12 15:40:17

要生成具有 x、y、z 样本点的拉盖尔多项式的伪范德蒙矩阵,请使用 Python Numpy 中的 laguerre.lagvander3d()。参数 x、y、z 返回一个点数组。dtype 转换为 float64 或 complex128,具体取决于元素是否为复数。如果 x 是标量,则转换为一维数组。参数 deg 是 [x_deg, y_deg, z_deg] 形式的最大度数列表。

步骤

首先,导入所需的库 −

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

使用 numpy.array() 方法 − 创建点坐标数组,所有数组的形状相同

x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

显示数组 −

print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

显示数据类型 −

print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

检查两个数组的维度 −

print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

检查两个数组的形状 −

print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

要生成具有 x、y、z 采样点的拉盖尔多项式的伪范德蒙矩阵,请使用 Python 中的 laguerre.lagvander3d() −

x_deg, y_deg, z_deg = 2, 3, 4
print("\n结果...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))

示例

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

# 使用 numpy.array() 方法创建点坐标数组,所有数组的形状相同
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

# 显示数组
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

# 显示数据类型
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

# 检查两个数组的维度
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# 检查两个数组的形状
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

# 要生成具有 x、y、z 样本点的拉盖尔多项式的伪范德蒙矩阵,请使用 Python Numpy 中的 laguerre.lagvander3d()

x_deg, y_deg, z_deg = 2, 3, 4
print("\n结果...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))

输出

Array1...
   [1.5 2.3]

Array2...
   [3.7 4.4]

Array3...
   [5.3 6.6]

Array1 datatype...
float64

Array2 datatype...
float64

Array3 datatype...
float64

Dimensions of Array1...
1

Dimensions of Array2...
1

Dimensions of Array3...
1

Shape of Array1...
(2,)

Shape of Array2...
(2,)

Shape of Array3...
(2,)

结果...
  [[ 1.          -4.3        4.445       2.42216667 -2.30432917
    -2.7          11.61     -12.0015    -6.53985     6.22168875
     0.445       -1.9135     1.978025    1.07786417 -1.02542648
     1.99283333  -8.56918333 8.85814417  4.82697447 -4.59214397
    -0.5          2.15      -2.2225     -1.21108333  1.15216458
     1.35        -5.805      6.00075     3.269925   -3.11084437
    -0.2225       0.95675   -0.9890125  -0.53893208  0.51271324
    -0.99641667  4.28459167 -4.42907208 -2.41348724  2.29607199
    -0.875       3.7625     -3.889375   -2.11939583  2.01628802
     2.3625     -10.15875   10.5013125   5.72236875 -5.44397766
   -0.389375     1.6743125  -1.73077188 -0.94313115  0.89724817
   -1.74372917   7.49803542 -7.75087615 -4.22360266  4.01812598]
  [ 1.          -5.6         9.58       -1.376      -7.3226
   -3.4         19.04      -32.572       4.6784      24.89684
    1.88       -10.528      18.0104     -2.58688    -13.766488
    2.64266667 -14.79893333 25.31674667 -3.63630933 -19.35119093
   -1.3         7.28       -12.454       1.7888      9.51938
    4.42       -24.752      42.3436     -6.08192    -32.365892
   -2.444      13.6864     -23.41352     3.362944    17.8964344
   -3.43546667 19.23861333 -32.91177067  4.72720213  25.15654821
   -0.955      5.348       -9.1489       1.31408     6.993083
    3.247     -18.1832     31.10626     -4.467872   -23.7764822
   -1.7954     10.05424    -17.199932    2.4704704   13.14699604
   -2.52374667 14.13298133 -24.17749307  3.47267541  18.48038734]]

相关文章


有用资源