使用 Python 和 Frobenius 范数计算线性代数中矩阵的条件数
要计算线性代数中矩阵的条件数,请在 Python 中使用 numpy.linalg.cond() 方法。此方法能够根据 p 值返回使用七种不同范数之一计算出的条件数。返回矩阵的条件数。可能为无穷大。
x 的条件数定义为 x 的范数乘以 x 的逆的范数;范数可以是通常的 L2 范数或许多其他矩阵范数之一。第一个参数是 x,即需要查找其条件数的矩阵。第二个参数是 p,即条件数计算中使用的范数的阶数。“fro”作为参数设置的是 Frobenius 范数。
步骤
首先,导入所需的库:
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...\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)
要计算线性代数中矩阵的条件数,请在 Python 中使用 numpy.linalg.cond() 方法。此方法能够根据 p 值返回使用七种不同范数之一计算出的条件数:
print("\nResult...\n",LA.cond(arr, 'fro'))示例
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...\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 condition number of a matrix in linear algebra, use the numpy.linalg.cond() method in Python
print("\nResult...\n",LA.cond(arr, 'fro'))输出
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... 5.000000000000001
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP