เพื่อลบ係เล็กน้อยที่ท้ายของพหุนาม Hermite_e ให้ใช้เมธอด hermite_e.hermetrim() ใน Python Numpy เมธอดคืนค่าอาร์เรย์ 1-d ที่ลบศูนย์ท้ายออก หากชุดที่ได้จะว่างเปล่า จะคืนชุดที่มีศูนย์เดียว
"เล็ก" หมายถึง "เล็กในค่าสัมบูรณ์" และควบคุมโดยพารามิเตอร์ tol "ท้าย" หมายถึง係อันดับสูงสุด เช่นใน [0, 1, 1, 0, 0] (ซึ่งแทน 0 + x + x**2 + 0*x**3 + 0*x**4) ทั้ง係อันดับ 3 และ 4 จะถูก "trim" พารามิเตอร์ c คืออาร์เรย์ 1-d ของ係 เรียงจากอันดับต่ำสุดไปสูงสุด พารามิเตอร์ tol คือองค์ประกอบท้ายที่มีค่าสัมบูรณ์น้อยกว่าหรือเท่ากับ tol จะถูกลบ
ขั้นตอน
ก่อนอื่น import ไลบรารีที่จำเป็น:
import numpy as np
from numpy.polynomial import hermite_e as H
สร้างอาร์เรย์ด้วย numpy.array() นี่คืออาร์เรย์ 1-d ของ係:
c = np.array([0, 5, 0, 0, 9, 0])
แสดงอาร์เรย์:
print("Our Array...\n", c)
ตรวจสอบมิติ:
print("\nDimensions of our Array...\n", c.ndim)
ดึง datatype:
print("\nDatatype of our Array object...\n", c.dtype)
ดึง shape:
print("\nShape of our Array object...\n", c.shape)
ลบ係เล็กน้อยที่ท้ายด้วย hermite_e.hermetrim():
print("\nResult...\n", H.hermetrim((c)))
ตัวอย่าง
import numpy as np
from numpy.polynomial import hermite_e 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_e polynomial
print("\nResult...\n", H.hermetrim((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.]