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

ประเมินอนุกรม Hermite_e 3 มิติ ที่จุด (x,y,z) ด้วย Python

บทนำ

การประเมินอนุกรม Hermite_e 3 มิติ (3D Hermite_e series) ที่จุดเฉพาะ (x, y, z) สามารถทำได้อย่างมีประสิทธิภาพด้วยเมธอด hermite.hermeval3d() ในไลบรารี NumPy ของ Python เมธอดนี้จะส่งคืนค่าของพหุนามมิติหลาย (multidimensional polynomial) ที่จุดที่สร้างจากคู่ค่าที่ตรงกันของ x, y และ z

พารามิเตอร์หลัก

พารามิเตอร์ที่ 1: x, y, z

อนุกรม 3 มิติจะถูกประเมินที่จุด (x, y, z) โดยที่ x, y และ z ต้องมีรูปร่าง (shape) เหมือนกัน หาก x, y หรือ z เป็นลิสต์หรือทูเพิล จะถูกแปลงเป็น ndarray ก่อน มิฉะนั้นจะคงค่าเดิมและถือเป็นสเกลาร์ (scalar) หากไม่ใช่ ndarray

พารามิเตอร์ที่ 2: C (สัมประสิทธิ์)

อาร์เรย์ของสัมประสิทธิ์ที่เรียงลำดับไว้ โดยสัมประสิทธิ์ของพจน์ที่มีมัลติดีกรี (multidegree) i, j, k จะอยู่ใน c[i, j, k] หาก c มีมิติมากกว่า 3 ดัชนีที่เหลือจะนับเป็นชุดสัมประสิทธิ์หลายชุด

ขั้นตอนการใช้งาน

1. นำเข้าไลบรารีที่จำเป็น

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

2. สร้างอาร์เรย์ 3 มิติของสัมประสิทธิ์

c = np.arange(24).reshape(2, 2, 6)

3. แสดงอาร์เรย์ ตรวจสอบมิติ ชนิดข้อมูล และรูปร่าง

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)

4. ประเมินอนุกรม Hermite_e 3 มิติ

print("\nResult...\n", H.hermeval3d([1, 2], [1, 2], [1, 2], c))

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

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

# สร้างอาร์เรย์ 3 มิติของสัมประสิทธิ์
c = np.arange(24).reshape(2, 2, 6)

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

# ประเมินอนุกรม Hermite_e 3 มิติ ที่จุด (x, y, z)
print("\nResult...\n", H.hermeval3d([1, 2], [1, 2], [1, 2], c))

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

Our Array...
 [[[ 0  1  2  3  4  5]
   [ 6  7  8  9 10 11]]
  [[12 13 14 15 16 17]
   [18 19 20 21 22 23]]]
Dimensions of our Array... 3
Datatype of our Array object... int64
Shape of our Array object... (2, 2, 6)
Result...
 [ 212. -2484.]