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

สร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ใน Python


ในการสร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ให้ใช้ hermite_e.hermevander() ใน Python Numpy เมธอดจะคืนค่าเมทริกซ์เทียม-Vandermonde รูปร่างของเมทริกซ์ที่ส่งคืนคือ x.shape + (deg + 1,) โดยที่ดัชนีสุดท้ายคือระดับของ Hermite_epolynomial ที่สอดคล้องกัน dtype จะเหมือนกับ x ที่แปลงแล้ว

พารามิเตอร์ x ส่งกลับ Array of points dtype ถูกแปลงเป็น float64 หรือ complex128 ขึ้นอยู่กับว่าองค์ประกอบใดที่ซับซ้อน ถ้า x เป็นสเกลาร์ จะถูกแปลงเป็นอาร์เรย์ 1 มิติ พารามิเตอร์ deg คือระดับของเมทริกซ์ผลลัพธ์

ขั้นตอน

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

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

สร้างอาร์เรย์ -

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

ในการสร้างเมทริกซ์ Vandermonde ของพหุนาม Hermite_e ให้ใช้ hermite_e.hermevander() ใน Python Numpy -

print("\nResult...\n",H.hermevander(x, 2))

ตัวอย่าง

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

# Create an array
x = np.array([0, 1, -1, 2])

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

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

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

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

# To generate a Vandermonde matrix of the Hermite_e polynomial, use the hermite_e.hermevander() in Python Numpy
print("\nResult...\n",H.hermevander(x, 2))

ผลลัพธ์

Our Array...
   [ 0 1 -1 2]

Dimensions of our Array...
1

Datatype of our Array object...
int64

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

Result...
   [[ 1. 0. -1.]
   [ 1. 1. 0.]
   [ 1. -1. 0.]
   [ 1. 2. 3.]]