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

สร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ด้วยจุด float array ใน Python


บทนำ

การสร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ใช้เมธอด hermite_e.hermvander() ใน NumPy คืนค่า pseudo-Vandermonde matrix รูปร่าง: x.shape + (deg + 1,) ดัชนีสุดท้ายคือดีกรีของพหุนาม Hermite dtype เหมือน x ที่แปลงแล้ว

พารามิเตอร์

  • x: อาร์เรย์จุด dtype แปลงเป็น float64 หรือ complex128 สเกลาร์แปลงเป็น 1-D array
  • deg: ดีกรีของเมทริกซ์ที่ได้

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

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

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

2. สร้างอาร์เรย์

x = np.array([0, 3.5, -1.4, 2.5])

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

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

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

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

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

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

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

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

7. สร้างเมทริกซ์ Vandermonde

print("\nResult...\n", H.hermevander(x, 2))

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

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

x = np.array([0, 3.5, -1.4, 2.5])
print("Our Array...\n", x)
print("\nDimensions of our Array...\n", x.ndim)
print("\nDatatype of our Array object...\n", x.dtype)
print("\nShape of our Array object...\n", x.shape)
print("\nResult...\n", H.hermevander(x, 2))

ผลลัพธ์ที่คาดหวัง

Our Array...   [ 0. 3.5 -1.4 2.5]
Dimensions of our Array... 1
Datatype of our Array object... float64
Shape of our Array object... (4,)
Result...   [[ 1. 0. -1. ] [ 1. 3.5 11.25] [ 1. -1.4 0.96] [ 1. 2.5 5.25]]