使用Python計算線性代數中矩陣的條件數(無窮範數)
在Python中,可以使用numpy.linalg.cond()方法計算線性代數中矩陣的條件數。此方法可以根據p的值返回使用七種不同範數之一計算的條件數。
返回矩陣的條件數。可能為無窮大。x的條件數定義為x的範數乘以x的逆的範數;範數可以是通常的L2範數或許多其他矩陣範數之一。第一個引數是x,即需要計算條件數的矩陣。第二個引數是p,用於條件數計算的範數的階數。“inf”引數設定為正無窮範數。
步驟
首先,匯入所需的庫:
import numpy as np from numpy import linalg as LA
建立一個數組:
arr = np.array([[ 1, 1, 0], [1, 0, 1], [1, 0, 0]])
顯示陣列:
print("Our Array...
",arr)檢查維度:
print("
Dimensions of our Array...
",arr.ndim)獲取資料型別:
print("
Datatype of our Array object...
",arr.dtype)獲取形狀:
print("
Shape of our Array object...
",arr.shape)在Python中,可以使用numpy.linalg.cond()方法計算線性代數中矩陣的條件數。此方法可以根據p的值返回使用七種不同範數之一計算的條件數:
print("
Result...
",LA.cond(arr, np.inf))示例
import numpy as np
from numpy import linalg as LA
# Create an array
arr = np.array([[ 1, 1, 0],
[1, 0, 1],
[1, 0, 0]])
# Display the array
print("Our Array...
",arr)
# Check the Dimensions
print("
Dimensions of our Array...
",arr.ndim)
# Get the Datatype
print("
Datatype of our Array object...
",arr.dtype)
# Get the Shape
print("
Shape of our Array object...
",arr.shape)
# To compute the condition number of a matrix in linear algebra, use the numpy.linalg.cond() method in Python
print("
Result...
",LA.cond(arr, np.inf))輸出
Our Array... [[1 1 0] [1 0 1] [1 0 0]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (3, 3) Result... 4.0
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP