Python numpy.linalg.norm(矩阵范数Matrix norm)
flyfish
import numpy as np
from numpy import linalg as LA
a = np.array([-3, -5, -7, 2, 6, 4, 0, 2, 8])
b = a.reshape((3, 3))
print(b)
'''
[[-3 -5 -7]
[ 2 6 4]
[ 0 2 8]]
'''
print( LA.norm(b))
#14.38749456993816
print(np.linalg.norm(b, ord=2))
#13.686302989309274
print(np.linalg.norm(b, ord=1))
#19.0
print(np.linalg.norm(b, ord=np.inf))
#15.0
A=⎡⎣⎢−3;5;72;6;40;2;8⎤⎦⎥, A = [ − 3 ; 5 ; 7 2 ; 6 ; 4 0 ; 2 ; 8 ] ,
∥A∥1=max(|−3|+2+0;5+6+2;7+4+8)=max(5,13,19)=19 ‖ A ‖ 1 = max ( | − 3 | + 2 + 0 ; 5 + 6 + 2 ; 7 + 4 + 8 ) = max ( 5 , 13 , 19 ) = 19
∥A∥∞=max(|−3|+5+7;2+6+4;0+2+8)=max(15,12,10)=15. ‖ A ‖ ∞ = max ( | − 3 | + 5 + 7 ; 2 + 6 + 4 ; 0 + 2 + 8 ) = max ( 15 , 12 , 10 ) = 15.
∥A∥2=λmax(A∗A)−−−−−−−−−√=σmax(A) ‖ A ‖ 2 = λ max ( A ∗ A ) = σ max ( A )
保持维度的方式
a=np.array([0,3,4,2,6,4]);
b = a.reshape((2, 3))
print(b)
print(np.linalg.norm(b,axis=1,keepdims=True))
#[[5. ]
#[7.48331477]]