在Python中評估多維陣列點x處的Hermite級數


要評估點x處的Hermite級數,請在Python Numpy中使用hermite.hermval()方法。第一個引數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 as H

建立一個係數陣列:

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

顯示陣列:

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

檢查維度:

print("
Dimensions of our Array...
",c.ndim)

獲取資料型別:

print("
Datatype of our Array object...
",c.dtype)

獲取形狀:

print("
Shape of our Array object...
",c.shape)

這裡,x是一個二維陣列:

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

要評估點x處的Hermite級數,請在Python Numpy中使用hermite.hermval()方法:

print("
Result...
",H.hermval(x,c))

示例

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

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

# Display the array
print("Our Array...
",c) # Check the Dimensions print("
Dimensions of our Array...
",c.ndim) # Get the Datatype print("
Datatype of our Array object...
",c.dtype) # Get the Shape print("
Shape of our Array object...
",c.shape) # Here, x is a 2D array x = np.array([[1,2],[3,4]]) # To evaluate a Hermite series at points x, use the hermite.hermval() method in Python Numpy print("
Result...
",H.hermval(x,c))

輸出

Our Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [[ 11. 51.]
   [115. 203.]]

更新於:2022年3月1日

瀏覽量:110

啟動您的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.