在 Python 中去除厄米多項式中小的尾隨係數
要從 Python NumPy 中的厄米多項式中去除小的尾隨係數,可以使用 `hermite.hermtrim()` 方法。該方法返回一個去除尾隨零的一維陣列。如果生成的序列為空,則返回包含單個零的序列。
“小”表示“絕對值小”,由引數 `tol` 控制;“尾隨”表示最高階係數,例如,在 `[0, 1, 1, 0, 0]`(表示 0 + x + x**2 + 0*x**3 + 0*x**4)中,第 3 階和第 4 階係數都將被“修剪”。引數 `c` 是一個從最低階到最高階排序的係數一維陣列。引數 `tol` 為:絕對值小於或等於 `tol` 的尾隨元素將被移除。
步驟
首先,匯入所需的庫:
import numpy as np from numpy.polynomial import hermite as H
使用 `numpy.array()` 方法建立一個數組。這是一個係數的一維陣列:
c = np.array([0,5,0, 0,9,0])
顯示陣列:
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)要從 Python NumPy 中的厄米多項式中去除小的尾隨係數,可以使用 `hermite.hermtrim()` 方法:
print("\nResult...\n",H.hermtrim((c)))示例
import numpy as np
from numpy.polynomial import hermite as H
# Create an array using the numpy.array() method
# This is the 1-d array of coefficients
c = np.array([0,5,0, 0,9,0])
# 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 remove small trailing coefficients from Hermite polynomial, use the hermite.hermtrim() method in Python Numpy.
print("\nResult...\n",H.hermtrim((c)))輸出
Our Array... [0 5 0 0 9 0] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (6,) Result... [0. 5. 0. 0. 9.]
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP