在 Python 中計算復厄米特矩陣或實對稱矩陣的特徵值
要計算復厄米特矩陣或實對稱矩陣的特徵值,可以使用 numpy.eigvalsh() 方法。該方法按升序返回特徵值,每個特徵值根據其重數重複。
第一個引數 a 是一個複數或實數矩陣,其特徵值需要計算。第二個引數 UPLO 指定計算是在 a 的下三角部分('L',預設)還是上三角部分('U')進行。無論此值如何,在計算中只會考慮對角線的實部,以保持厄米特矩陣的概念。因此,對角線的虛部將始終被視為零。
步驟
首先,匯入所需的庫 -
import numpy as np from numpy import linalg as LA
使用 numpy.array() 方法建立一個二維 numpy 陣列 -
arr = np.array([[5+2j, 9-2j], [0+2j, 2-1j]])
顯示陣列 -
print("Our Array...\n",arr)檢查維度 -
print("\nDimensions of our Array...\n",arr.ndim)
獲取資料型別 -
print("\nDatatype of our Array object...\n",arr.dtype)獲取形狀 -
print("\nShape of our Array object...\n",arr.shape)
要計算復厄米特矩陣或實對稱矩陣的特徵值,可以使用 numpy.eigvalsh() 方法 -
print("\nResult...\n",LA.eigvalsh(arr))示例
from numpy import linalg as LA
import numpy as np
# Creating a 2D numpy array using the numpy.array() method
arr = np.array([[5+2j, 9-2j], [0+2j, 2-1j]])
# Display the array
print("Our Array...\n",arr)
# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)
# Get the Shape
print("\nShape of our Array object...\n",arr.shape)
# To compute the eigenvalues of a complex Hermitian or real symmetric matrix, use the numpy.eigvalsh() method
print("\nResult...\n",LA.eigvalsh(arr))輸出
Our Array... [[5.+2.j 9.-2.j] [0.+2.j 2.-1.j]] Dimensions of our Array... 2 Datatype of our Array object... complex128 Shape of our Array object... (2, 2) Result... [1. 6.]
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP