在Python中生成Hermite多项式和x、y、z样本点的伪范德蒙德矩阵

在Python中生成Hermite多项式和x、y、z样本点的伪范德蒙德矩阵

要生成Hermite多项式和x、y、z样本点的伪范德蒙德矩阵,可以使用Python中的NumPy库中的hermite.hermvander3d()方法。该方法返回伪范德蒙德矩阵。参数x、y、z是形状相同的点坐标数组。数据类型将根据元素是否为复数而转换为float64或complex128。标量将被转换为1-D数组。参数deg是形如[x_deg, y_deg, z_deg]的最大阶列表。

步骤

首先,导入所需的库。

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

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

x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 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多项式和x,y,z样本点的伪Vandermonde矩阵, 使用hermite.hermvander3d()函数 −

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

示例

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

# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])

# Display the arrays
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

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

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

# To generate a pseudo Vandermonde matrix of the Hermite polynomial and x, y, z sample points, use the hermite.hermvander3d() in Python Numpy
# The method returns the pseudo-Vandermonde matrix.

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

输出

Array1...
   [1 2]

Array2...
   [3 4]

Array3...
   [5 6]

Array1 datatype...
int64

Array2 datatype...
int64

Array3 datatype...
int64

Dimensions of Array1...
1

Dimensions of Array2...
1

Dimensions of Array3...
1

Shape of Array1...
(2,)

Shape of Array2...
(2,)

Shape of Array3...
(2,)

Result...
   [[1.0000000e+00 1.0000000e+01 9.8000000e+01 9.4000000e+02 8.8120000e+03
     6.0000000e+00 6.0000000e+01 5.8800000e+02 5.6400000e+03 5.2872000e+04
     3.4000000e+01 3.4000000e+02 3.3320000e+03 3.1960000e+04 2.9960800e+05
     1.8000000e+02 1.8000000e+03 1.7640000e+04 1.6920000e+05 1.5861600e+06
     2.0000000e+00 2.0000000e+01 1.9600000e+02 1.8800000e+03 1.7624000e+04
     1.2000000e+01 1.2000000e+02 1.1760000e+03 1.1280000e+04 1.0574400e+05
     6.8000000e+01 6.8000000e+02 6.6640000e+03 6.3920000e+04 5.9921600e+05
     3.6000000e+02 3.6000000e+03 3.5280000e+04 3.3840000e+05 3.1723200e+06
     2.0000000e+00 2.0000000e+01 1.9600000e+02 1.8800000e+03 1.7624000e+04
     1.2000000e+01 1.2000000e+02 1.1760000e+03 1.1280000e+04 1.0574400e+05
     6.8000000e+01 6.8000000e+02 6.6640000e+03 6.3920000e+04 5.9921600e+05
     3.6000000e+02 3.6000000e+03 3.5280000e+04 3.3840000e+05 3.1723200e+06]
  [1.0000000e+00 1.2000000e+01 1.4200000e+02 1.6560000e+03 1.9020000e+04
     8.0000000e+00 9.6000000e+01 1.1360000e+03 1.3248000e+04 1.5216000e+05
     6.2000000e+01 7.4400000e+02 8.8040000e+03 1.0267200e+05 1.1792400e+06
     4.6400000e+02 5.5680000e+03 6.5888000e+04 7.6838400e+05 8.8252800e+06
     4.0000000e+00 4.8000000e+01 5.6800000e+02 6.6240000e+03 7.6080000e+04
     3.2000000e+01 3.8400000e+02 4.5440000e+03 5.2992000e+04 6.0864000e+05
     2.4800000e+02 2.9760000e+03 3.5216000e+04 4.1068800e+05 4.7169600e+06
     1.8560000e+03 2.2272000e+04 2.6355200e+05 3.0735360e+06 3.5301120e+07
     1.4000000e+01 1.6800000e+02 1.9880000e+03 2.3184000e+04 2.6628000e+05
     1.1200000e+02 1.3440000e+03 1.5904000e+04 1.8547200e+05 2.1302400e+06
     8.6800000e+02 1.0416000e+04 1.2325600e+05 1.4374080e+06 1.6509360e+07
     6.4960000e+03 7.7952000e+04 9.2243200e+05 1.0757376e+07 1.2355392e+08]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程