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

ประเมินชุด Hermite_e ที่ทูเพิลของจุด x ใน Python


ในการประเมินชุด Hermite_e ที่จุด x ให้ใช้เมธอด hermite.hermeval() ใน Python Numpy พารามิเตอร์ที่ 1 คือ x ถ้า x เป็นรายการหรือทูเพิล จะถูกแปลงเป็น ndarray ไม่เช่นนั้น จะไม่เปลี่ยนแปลงและถือเป็น สเกลาร์ ไม่ว่าในกรณีใด x หรือองค์ประกอบของมันจะต้องสนับสนุนการบวกและการคูณด้วยตัวมันเองและกับองค์ประกอบของค

พารามิเตอร์ตัวที่ 2, C, อาร์เรย์ของสัมประสิทธิ์ที่จัดลำดับเพื่อให้สัมประสิทธิ์สำหรับเงื่อนไขของดีกรี nare อยู่ใน c[n] ถ้า c มีหลายมิติ ดัชนีที่เหลือจะระบุพหุนามพหุนามหลายตัว ในกรณีสองมิติ สัมประสิทธิ์อาจคิดว่าจัดเก็บไว้ในคอลัมน์ของค

พารามิเตอร์ตัวที่ 3 เทนเซอร์ ถ้า True รูปร่างของอาร์เรย์สัมประสิทธิ์จะถูกขยายด้วยตัวที่อยู่ทางขวา หนึ่งตัวสำหรับแต่ละมิติของ x สเกลาร์มีมิติ 0 สำหรับการดำเนินการนี้ ผลที่ได้คือทุกคอลัมน์ของสัมประสิทธิ์ใน c ถูกประเมินสำหรับทุกองค์ประกอบของ x หากเป็นเท็จ x จะถูกถ่ายทอดบนคอลัมน์ของ c สำหรับการประเมิน คีย์เวิร์ดนี้มีประโยชน์เมื่อ c เป็นแบบหลายมิติ ค่าเริ่มต้นคือ True

ขั้นตอน

ขั้นแรก นำเข้าไลบรารีที่จำเป็น -

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

สร้างอาร์เรย์ของสัมประสิทธิ์ -

c = np.array([1, 2, 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)

โดยที่ x เป็นทูเพิล -

x = (5, 10, 15)

ในการประเมินชุด Hermite_e ที่จุด x ให้ใช้วิธี hermite.hermeval() ใน Python Numpy -

print("\nResult...\n",H.hermeval(x,c))

ตัวอย่าง

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

# Create an array of coefficients
c = np.array([1, 2, 3])

# Display the array
print("Our Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# Here, x is a tuple
x = (5, 10, 15)

# To evaluate a Hermite_e series at points x, use the hermite.hermeval() method in Python Numpy
print("\nResult...\n",H.hermeval(x,c))

ผลลัพธ์

Our Array...
   [1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result...
   [ 83. 318. 703.]