在 Python 中使用多維繫數陣列評估 Hermite_e 多項式級數在點 x 的值


要評估 Hermite_e 多項式級數在點 x 的值,可以使用 Python Numpy 中的 hermite.hermeval() 方法。第一個引數 x,如果 x 是列表或元組,則將其轉換為 ndarray,否則保持不變並將其視為標量。在這兩種情況下,x 或其元素都必須支援自身之間的加法和乘法,以及與 c 的元素之間的加法和乘法。

第二個引數 C,一個係數陣列,其排序方式是 n 次項的係數包含在 c[n] 中。如果 c 是多維的,則其餘索引列舉多個多項式。在二維情況下,可以認為係數儲存在 c 的列中。

第三個引數 tensor,如果為 True,則係數陣列的形狀在右側擴充套件為 1,每個維度對應 x 的一個維度。對於此操作,標量具有維度 0。結果是,c 中的每一列係數都會針對 x 的每個元素進行評估。如果為 False,則 x 會在評估期間廣播到 c 的列上。此關鍵字在 c 為多維時很有用。預設值為 True。

步驟

首先,匯入所需的庫 -

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

建立一個多維繫數陣列 -

c = np.array([[1,2],[3,4]])

顯示陣列 -

print("Our Array...\n",c)

檢查維度 -

print("\nDimensions of our Array...\n",c.ndim)

獲取資料型別 -

print("\nDatatype of our Array object...\n",c.dtype)

獲取形狀 -

print("\nShape of our Array object...\n",c.shape)

要評估 Hermite_e 多項式級數在點 x 的值,可以使用 Python Numpy 中的 hermite.hermeval() 方法 -

print("\nResult...\n",H.hermeval([1,2],c))

示例

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

# Create a multidimensional of coefficients
c = np.array([[1,2],[3,4]])

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To evaluate a Hermite_e series at points x, use the hermite.hermeval() method in Python Numpy
print("\nResult...\n",H.hermeval([1,2],c))

輸出

Our Array...
   [[1 2]
   [3 4]]

Dimensions of our Array...
2

Datatype of our Array object...
int64

Shape of our Array object...
(2, 2)

Result...
   [[ 4. 7.]
   [ 6. 10.]]

更新於: 2022-03-08

90 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告