使用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