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

อินทิเกรตอนุกรมเลจันเดอร์บน axis 1 ใน Python


บทนำ

การอินทิเกรตอนุกรมเลจันเดอร์ใช้เมธอด polynomial.legendre.legint() ใน Python พารามิเตอร์ axis ระบุแกนที่ทำการอินทิเกรชัน (Default: 0) ตั้งค่า axis=1 เพื่ออินทิเกรตตามแกนที่ 1

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

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

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

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. อินทิเกรตบน axis=1

print("\nResult...\n", L.legint(c, axis=1))

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

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

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", L.legint(c, axis=1))

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

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...   [[0.16666667 0. 0.33333333] [0.5 2. 1. ]]