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

การสร้างเมทริกซ์ Vandermonde ของพหุนาม Laguerre ใน Python


บทนำ

ในการสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนาม Laguerre สามารถใช้ laguerre.lagvander() จาก NumPy คล้ายกับตัวอย่างก่อนหน้า แต่ใช้จุดข้อมูลเป็นจำนวนเต็ม

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

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

import numpy as np
from numpy.polynomial import laguerre as L

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

x = np.array([0, 1, -1, 2])

3. แสดงอาเรย์และตรวจสอบคุณสมบัติ

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)

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

print("\nResult...\n", L.lagvander(x, 2))

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

import numpy as np
from numpy.polynomial import laguerre as L

# สร้างอาเรย์
x = np.array([0, 1, -1, 2])

# แสดงอาเรย์
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)

# สร้างเมทริกซ์ Vandermonde ของพหุนาม Laguerre
print("\nResult...\n", L.lagvander(x, 2))

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

Our Array...   [ 0 1 -1 2]
Dimensions of our Array... 1
Datatype of our Array object... int64
Shape of our Array object... (4,)
Result...   [[ 1. 1. 1. ]
             [ 1. 0. -0.5]
             [ 1. 2. 3.5]
             [ 1. -1. -1. ]]