Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ประเมินอนุกรม Hermite_e ที่จุด x เมื่อสัมประสิทธิ์เป็นหลายมิติใน Python


บทนำ

การประเมินอนุกรม Hermite_e ที่จุด x ใช้เมธอด hermite.hermeval() ใน NumPy เมื่อสัมประสิทธิ์เป็นหลายมิติ

พารามิเตอร์

  • x: list/tuple แปลงเป็น ndarray มิฉะนั้นเป็น scalar
  • C: อาร์เรย์สัมประสิทธิ์ c[n] สำหรับพจน์ดีกรี n หลายมิติ = หลายพหุนาม
  • tensor: True (default) = ขยายรูปร่าง c ด้วย ones ต่อมิติของ x False = broadcast x ไปยังคอลัมน์ของ c

ขั้นตอนการทำงาน

1. นำเข้าไลบรารี

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

2. สร้างอาร์เรย์สัมประสิทธิ์หลายมิติ

c = np.arange(4).reshape(2, 2)

3. แสดงอาร์เรย์

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

4. ตรวจสอบมิติ

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

5. ตรวจสอบชนิดข้อมูล

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

6. ตรวจสอบรูปร่าง

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

7. ประเมินอนุกรม (default tensor=True)

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

ตัวอย่างโค้ดสมบูรณ์

import numpy as np
from numpy.polynomial import hermite_e 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)
print("\nResult...\n", H.hermeval([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...   [[2. 4.] [4. 7.]]