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

pythonnumpyserver side programmingprogramming

要生成 Hermite_e 多项式的伪范德蒙矩阵和 x、y、z 样本点,请使用 Python Numpy 中的 hermite_e.hermevander3d()。该方法返回伪范德蒙矩阵。参数 x、y、z 是点坐标数组,所有数组的形状相同。dtype 将转换为 float64 或 complex128,具体取决于是否有任何元素是复数。标量将转换为一维数组。参数 deg 是 [x_deg, y_deg, z_deg] 形式的最大度数列表。

步骤

首先,导入所需的库 −

import numpy as np
from numpy.polynomial import hermite_e as H

使用 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)

要生成 Hermite_e 多项式和 x、y、z 样本点的伪 Vandermonde 矩阵,请使用 Python 中的 hermite_e.hermevander3d() −

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

示例

import numpy as np
from numpy.polynomial import hermite_e as H

# 使用 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)

# 要生成 Hermite_e 多项式和 x、y、z 样本点的伪 Vandermonde 矩阵,请使用 Python Numpy 中的 hermite_e.hermevander3d()
x_deg, y_deg, z_deg = 2, 3, 4
print("\n结果...\n",H.hermevander3d(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.00000000e+00 5.30000000e+00 2.70900000e+01 1.32977000e+02
     6.23508100e+02 3.70000000e+00 1.96100000e+01 1.00233000e+02
     4.92014900e+02 2.30697997e+03 1.26900000e+01 6.72570000e+01
     3.43772100e+02 1.68747813e+03 7.91231779e+03 3.95530000e+01
     2.09630900e+02 1.07149077e+03 5.25963928e+03 2.46616159e+04
     1.50000000e+00 7.95000000e+00 4.06350000e+01 1.99465500e+02
     9.35262150e+02 5.55000000e+00 2.94150000e+01 1.50349500e+02
     7.38022350e+02 3.46046996e+03 1.90350000e+01 1.00885500e+02
     5.15658150e+02 2.53121720e+03 1.18684767e+04 5.93295000e+01
     3.14446350e+02 1.60723616e+03 7.88945892e+03 3.69924238e+04
     1.25000000e+00 6.62500000e+00 3.38625000e+01 1.66221250e+02
     7.79385125e+02 4.62500000e+00 2.45125000e+01 1.25291250e+02
     6.15018625e+02 2.88372496e+03 1.58625000e+01 8.40712500e+01
     4.29715125e+02 2.10934766e+03 9.89039724e+03 4.94412500e+01
     2.62038625e+02 1.33936346e+03 6.57454910e+03 3.08270198e+04]
    [1.00000000e+00 6.60000000e+00 4.25600000e+01 2.67696000e+02
     1.63911360e+03 4.40000000e+00 2.90400000e+01 1.87264000e+02
     1.17786240e+03 7.21209984e+03 1.83600000e+01 1.21176000e+02
     7.81401600e+02 4.91489856e+03 3.00941257e+04 7.19840000e+01
     4.75094400e+02 3.06363904e+03 1.92698289e+04 1.17989953e+05
     2.30000000e+00 1.51800000e+01 9.78880000e+01 6.15700800e+02
     3.76996128e+03 1.01200000e+01 6.67920000e+01 4.30707200e+02
     2.70908352e+03 1.65878296e+04 4.22280000e+01 2.78704800e+02
     1.79722368e+03 1.13042667e+04 6.92164891e+04 1.65563200e+02
     1.09271712e+03 7.04636979e+03 4.43206064e+04 2.71376893e+05
     4.29000000e+00 2.83140000e+01 1.82582400e+02 1.14841584e+03
     7.03179734e+03 1.88760000e+01 1.24581600e+02 8.03362560e+02
     5.05302970e+03 3.09399083e+04 7.87644000e+01 5.19845040e+02
     3.35221286e+03 2.10849148e+04 1.29103799e+05 3.08811360e+02
     2.03815498e+03 1.31430115e+04 8.26675658e+04 5.06176900e+05]]

相关文章