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

การสร้างเมทริกซ์ Vandermonde แบบปลอมของพหุนาม Laguerre และจุด x, y จำนวนเต็มใน Python


บทนำ

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

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

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

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

2. สร้างอาเรย์พิกัดจุดจำนวนเต็ม

x = np.array([1, 2])
y = np.array([3, 4])

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

print("Array1...\n", x)
print("\nArray2...\n", y)
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)

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

x_deg, y_deg = 2, 3
print("\nResult...\n", L.lagvander2d(x, y, [x_deg, y_deg]))

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

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

# สร้างอาเรย์พิกัดจุด
x = np.array([1, 2])
y = np.array([3, 4])

# แสดงอาเรย์
print("Array1...\n", x)
print("\nArray2...\n", y)

# แสดงชนิดข้อมูล
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)

# ตรวจสอบมิติ
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)

# ตรวจสอบรูปร่าง
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)

# สร้างเมทริกซ์ Vandermonde 2 มิติ
x_deg, y_deg = 2, 3
print("\nResult...\n", L.lagvander2d(x, y, [x_deg, y_deg]))

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

Array1...   [1 2]
Array2...   [3 4]
Array1 datatype... int64
Array2 datatype... int64
Dimensions of Array1... 1
Dimensions of Array2... 1
Shape of Array1... (2,)
Shape of Array2... (2,)
Result...   [[ 1. -2. -0.5 1. 0. -0. -0. 0.5 1. 0.25 -0.5 ]
             [ 1. -3. 1. 2.33333333 -1. 3. -1. -2.33333333 -1. 3. -1. -2.33333333]]