在Python中生成给定次数和x、y、z样本点的伪范德蒙德矩阵

在Python中生成给定次数和x、y、z样本点的伪范德蒙德矩阵

要生成给定次数和x、y、z样本点的伪范德蒙德矩阵,请在Python Numpy中使用polynomial.polyvander3d()方法。该方法返回次数为deg且样本点为(x, y, z)的伪范德蒙德矩阵。参数x、y、z是点坐标的数组,形状相同。dtypes将根据元素是否为复数来转换为float64或complex128。标量将转换为1-D数组。参数deg是形如[x_deg, y_deg, z_deg]的最大次数列表。

步骤

首先,导入所需的库−

import numpy as np
from numpy.polynomial.polynomial import polyvander3d
使用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)

使用 polynomial.polyvander3d() 方法生成给定阶数和 x、y、z 样本点的伪 Vandermonde 矩阵。

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

示例

import numpy as np
from numpy.polynomial.polynomial import polyvander3d

# 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
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# Check the Shape
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 given degree and x, y, z sample points, use the polynomial.polyvander3d() in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",polyvander3d(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.00000e+00 5.00000e+00 2.50000e+01 1.25000e+02 6.25000e+02 3.00000e+00
1.50000e+01 7.50000e+01 3.75000e+02 1.87500e+03 9.00000e+00 4.50000e+01
2.25000e+02 1.12500e+03 5.62500e+03 2.70000e+01 1.35000e+02 6.75000e+02
3.37500e+03 1.68750e+04 1.00000e+00 5.00000e+00 2.50000e+01 1.25000e+02
6.25000e+02 3.00000e+00 1.50000e+01 7.50000e+01 3.75000e+02 1.87500e+03
9.00000e+00 4.50000e+01 2.25000e+02 1.12500e+03 5.62500e+03 2.70000e+01
1.35000e+02 6.75000e+02 3.37500e+03 1.68750e+04 1.00000e+00 5.00000e+00
2.50000e+01 1.25000e+02 6.25000e+02 3.00000e+00 1.50000e+01 7.50000e+01
3.75000e+02 1.87500e+03 9.00000e+00 4.50000e+01 2.25000e+02 1.12500e+03
5.62500e+03 2.70000e+01 1.35000e+02 6.75000e+02 3.37500e+03 1.68750e+04]
[1.00000e+00 6.00000e+00 3.60000e+01 2.16000e+02 1.29600e+03 4.00000e+00
2.40000e+01 1.44000e+02 8.64000e+02 5.18400e+03 1.60000e+01 9.60000e+01
5.76000e+02 3.45600e+03 2.07360e+04 6.40000e+01 3.84000e+02 2.30400e+03
1.38240e+04 8.29440e+04 2.00000e+00 1.20000e+01 7.20000e+01 4.32000e+02
2.59200e+03 8.00000e+00 4.80000e+01 2.88000e+02 1.72800e+03 1.03680e+04
3.20000e+01 1.92000e+02 1.15200e+03 6.91200e+03 4.14720e+04 1.28000e+02
7.68000e+02 4.60800e+03 2.76480e+04 1.65888e+05 4.00000e+00 2.40000e+01
1.44000e+02 8.64000e+02 5.18400e+03 1.60000e+01 9.60000e+01 5.76000e+02
3.45600e+03 2.07360e+04 6.40000e+01 3.84000e+02 2.30400e+03 1.38240e+04
8.29440e+04 2.56000e+02 1.53600e+03 9.21600e+03 5.52960e+04 3.31776e+05]]

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程