Python
 Computer >> コンピューター >  >> プログラミング >> Python

Pythonで指定した次数とx、y、zサンプル点から疑似ファンデルモンド行列を生成する方法


PythonのNumPyでは、多項式ユーティリティの polynomial.polyvander3d() 関数を使用することで、指定した次数とx、y、zのサンプル点から疑似ファンデルモンド行列(pseudo-Vandermonde行列)を生成できます。この関数は、引数として渡した次数 deg とサンプル点 (x, y, z) に対応する疑似ファンデルモンド行列を返します。

パラメータの概要

x、y、z は点の座標を表す配列で、すべて同じ形状である必要があります。要素に複素数が含まれるかどうかに応じて、データ型は float64 または complex128 に自動的に変換され、スカラー値は1次元配列へと変換されます。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)

最後に、polyvander3d() を呼び出して、指定した次数とサンプル点から疑似ファンデルモンド行列を生成します。

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

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

# polyvander3d()で疑似ファンデルモンド行列を生成
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]]

  1. Pythonでエルミート多項式とx・y・zサンプル点の疑似ファンデルモンド行列を生成する方法

    エルミート多項式とx、y、zのサンプル点から疑似ファンデルモンド行列を生成するには、PythonのNumPyが提供する hermite.hermvander3d() メソッドを使用します。このメソッドは、計算結果として疑似ファンデルモンド行列を返します。 エルミート多項式は、物理学や確率論などの分野で広く利用される直交多項式の一種です(NumPyの numpy.polynomial.hermite モジュールでは、物理学者が用いる形式のエルミート多項式が採用されています)。疑似ファンデルモンド行列とは、各サンプル点における多項式の値を次数ごとの列として並べた行列のことで、多項式による最小二乗近

  2. Pythonでチェビシェフ多項式とx、y、zサンプル点から疑似ファンデルモンド行列を生成する方法

    PythonのNumPyライブラリでは、numpy.polynomial.chebyshevモジュールのchebvander3d()関数を使うことで、チェビシェフ多項式とx、y、zのサンプル点から疑似ファンデルモンド行列を簡単に生成できます。このメソッドは、指定された次数degとサンプル点(x, y, z)に対応する疑似ファンデルモンド行列を返します。パラメータのx、y、zは点の座標を表す配列で、すべて同じ形状である必要があります。データ型は、要素に複素数が含まれるかどうかに応じてfloat64またはcomplex128へ自動的に変換されます。また、スカラー値は1次元配列として扱われます。パラ