在Python中評估係數為多維的埃爾米特級數在x點處的值
要評估x點處的埃爾米特級數,請在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.arange(4).reshape(2,2)
顯示陣列:
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)要評估x點處的埃爾米特級數,請在Python NumPy中使用hermite.hermval()方法:
print("\nResult...\n",H.hermval([1,2],c))示例
import numpy as np
from numpy.polynomial import hermite as H
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
# 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 series at points x, use the hermite.hermval() method in Python Numpy
print("\nResult...\n",H.hermval([1,2],c))輸出
Our Array... [[0 1] [2 3]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[ 4. 8.] [ 7. 13.]]
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP