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

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

ตัวอย่างนี้แสดงการใช้ legval() กับอาร์เรย์係ณหลายมิติ โดยไม่ระบุ tensor (จะใช้ค่าเริ่มต้น True) ให้ผลลัพธ์เหมือนตัวอย่างก่อนหน้า

ขั้นตอน

นำเข้าไลบรารีและสร้างอาร์เรย์係ณ:

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.legval([1, 2], c))

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

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.legval([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.]]