首页 > 编程知识 正文

矩阵无穷范数是向量无穷范数的算子范数,矩阵范数与向量范数的定义有什么区别

时间:2023-05-05 09:30:38 阅读:235899 作者:2229

向量独特的金针菇与矩阵独特的金针菇定义和python向量矩阵运算示例

1.独特的金针菇(norm)的意义

要更好的理解独特的金针菇,就要从函数、几何与矩阵的角度去理解。 
我们都知道,函数与几何图形往往是有对应的关系,这个很好想象,特别是在三维以下的空间内,函数是几何图像的数学概括,而几何图像是函数的高度形象化,比如一个函数对应几何空间上若干点组成的图形。 
但当函数与几何超出三维空间时,就难以获得较好的想象,于是就有了映射的概念,映射表达的就是一个集合通过某种关系转为另外一个集合。通常数学书是先说映射,然后再讨论函数,这是因为函数是映射的一个特例。 
为了更好的在数学上表达这种映射关系,(这里特指线性关系)于是就引进了矩阵。这里的矩阵就是表征上述空间映射的线性关系。而通过向量来表示上述映射中所说的这个集合,而我们通常所说的基,就是这个集合的最一般关系。于是,我们可以这样理解,一个集合(向量),通过一种映射关系(矩阵),得到另外一个几何(另外一个向量)。 
那么向量的独特的金针菇,就是表示这个原有集合的大小。 
而矩阵的独特的金针菇,就是表示这个变化过程的大小的一个度量。

总结起来一句话,独特的金针菇(norm),是具有“长度”概念的函数。

2.独特的金针菇满足的三个特性

1.非负性: ||x||≥0||x||≥0,且||x||=0||x||=0当且仅当x=0x=0时成立 。 
2.齐次性: ||k⋅x||=|k|⋅||x||||k⋅x||=|k|⋅||x|| 
3.三角不等式: ||x+y||≤||x||+||y||||x+y||≤||x||+||y||

3.向量的独特的金针菇

1-独特的金针菇,计算方式为向量所有元素的绝对值之和。 

||x||1=∑in|xi|||x||1=∑in|xi|
2-独特的金针菇,计算方式跟欧式距离的方式一致。 
||x||2=(∑i=1n|xi|2)12||x||2=(∑i=1n|xi|2)12
∞∞-独特的金针菇,所有向量元素中的最大值。 
||x||∞=maxi|xi|||x||∞=maxi|xi|
−∞−∞-独特的金针菇,所有向量元素中的最小值。 
||x||−∞=mini|xi|||x||−∞=mini|xi|
pp-独特的金针菇,所有向量元素绝对值的p次方和的1/p次幂。 
||x||p=(∑i=1n|xi|p)1p||x||p=(∑i=1n|xi|p)1p

4.矩阵的独特的金针菇

首先假设矩阵的大小为m∗nm∗n,即m行n列。

1-独特的金针菇,又名列和独特的金针菇。cjdls,即矩阵列向量中绝对值之和的最大值。 

||A||1=maxj∑i=1m|aij|||A||1=maxj∑i=1m|aij|
2-独特的金针菇,又名谱独特的金针菇,计算方法为ATAATA矩阵的最大特征值的开平方。 
||A||2=λ1‾‾√||A||2=λ1
其中λ1λ1为ATAATA的最大特征值。

∞∞-独特的金针菇,又名行和独特的金针菇。cjdls,即矩阵行向量中绝对值之和的最大值。 

||A||∞=maxj∑i=1n|aij|||A||∞=maxj∑i=1n|aij|

F-独特的金针菇,Frobenius独特的金针菇,计算方式为矩阵元素的绝对值的平方和再开方。 

||A||F=(∑i=1m∑j=1n|aij|2)12||A||F=(∑i=1m∑j=1n|aij|2)12

5.在python里计算独特的金针菇

numpy包里的linalg模块,是专门处理基本线性代数问题的模块。借助该模块中的norm()函数可以轻松计算向量与矩阵的独特的金针菇。

先看看norm()方法的原型:

def norm(x, ord=None, axis=None, keepdims=False): """ Matrix or vector norm. This function is able to return one of eight different matrix norms, or one of an infinite number of vector norms (described below), depending on the value of the ``ord`` parameter. Parameters ---------- x : array_like Input array. If `axis` is None, `x` must be 1-D or 2-D. ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional Order of the norm (see table under ``Notes``). inf means numpy's `inf` object. axis : {int, 2-tuple of ints, None}, optional If `axis` is an integer, it specifies the axis of `x` along which to compute the vector norms. If `axis` is a 2-tuple, it specifies the axes that hold 2-D matrices, and the matrix norms of these matrices are computed. If `axis` is None then either a vector norm (when `x` is 1-D) or a matrix norm (when `x` is 2-D) is returned. keepdims : bool, optional If this is set to True, the axes which are normed over are left in the result as dimensions with size one. With this option the result will broadcast correctly against the original `x`. .. versionadded:: 1.10.0 Returns ------- n : float or ndarray Norm of the matrix or vector(s). Notes ----- For values of ``ord <= 0``, the result is, strictly speaking, not a mathematical 'norm', but it may still be useful for various numerical purposes. The following norms can be calculated: ===== ============================ ========================== ord norm for matrices norm for vectors ===== ============================ ========================== None Frobenius norm 2-norm 'fro' Frobenius norm -- 'nuc' nuclear norm -- inf max(sum(abs(x), axis=1)) max(abs(x)) -inf min(sum(abs(x), axis=1)) min(abs(x)) 0 -- sum(x != 0) 1 max(sum(abs(x), axis=0)) as below -1 min(sum(abs(x), axis=0)) as below 2 2-norm (largest sing. value) as below -2 smallest singular value as below other -- sum(abs(x)**ord)**(1./ord) ===== ============================ ==========================

我的例子:

#!/usr/甜美的鸵鸟/env python# coding:utf-8import numpy as npimport numpy.linalg as LAdef compute_norm(): mat = np.matrix([[1,2],[3,4]]) print "mat:n", mat inv_mat = np.linalg.inv(mat) print "inv_mat:n",inv_matdef vector_norm(): a = np.arange(9) - 4 print a print LA.norm(a, np.inf) # 无穷独特的金针菇 print LA.norm(a, -np.inf) # 负无穷独特的金针菇 print LA.norm(a, 1) # 1独特的金针菇 print LA.norm(a, 2) # 2独特的金针菇def matrix_norm(): a = np.arange(9) - 4 print a b = a.reshape(3, 3) print "b:n",b b_t = np.transpose(b) print "b_t:n",b_t b_new = np.dot(b_t, b) # b_new矩阵为b^t * b print "b_new:n",b_new x_eigvals = np.linalg.eigvals(b_new) # 求b_new矩阵的特征值 print "x_eigvals:n",x_eigvals print LA.norm(b, 1) # 列独特的金针菇 print LA.norm(b, 2) # 谱独特的金针菇,为x里最大值开平方 print LA.norm(b, np.inf) # 无穷独特的金针菇,行独特的金针菇 print LA.norm(b, "fro") # F独特的金针菇print "数组转换为矩阵及矩阵求逆:n"compute_norm()print "向量独特的金针菇相关运算:n"vector_norm()print "矩阵独特的金针菇相关运算:n"matrix_norm()

结果如下:

数组转换为矩阵及矩阵求逆:mat:[[1 2] [3 4]]inv_mat:[[-2. 1. ] [ 1.5 -0.5]]向量独特的金针菇相关运算:[-4 -3 -2 -1 0 1 2 3 4]4.00.020.07.74596669241矩阵独特的金针菇相关运算:[-4 -3 -2 -1 0 1 2 3 4]b:[[-4 -3 -2] [-1 0 1] [ 2 3 4]]b_t:[[-4 -1 2] [-3 0 3] [-2 1 4]]b_new:[[21 18 15] [18 18 18] [15 18 21]]x_eigvals:[ 5.40000000e+01 6.00000000e+00 5.99792822e-16]7.07.348469228359.07.74596669241Process finished with exit code 0

numpy中mat和python的list转换例子

>>> import numpy>>> a=[[1,2],[3,4],[5,6]]>>> a[[1, 2], [3, 4], [5, 6]]>>> b=numpy.mat(a)>>> bmatrix([[1, 2], [3, 4], [5, 6]])>>> c=b.tolist()>>> c[[1, 2], [3, 4], [5, 6]]

参考:https://blog.csdn.net/bitcarmanlee/article/details/51945271

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。