向量范数

2017-12-14  本文已影响0人  python小玩家

参考:
http://blog.csdn.net/left_la/article/details/9159949

http://blog.csdn.net/bitcarmanlee/article/details/51945271

https://baike.baidu.com/item/%E8%8C%83%E6%95%B0/10856788?fr=aladdin

image.png image.png
#!/usr/bin/env python
#coding:utf-8

import numpy as np
import numpy.linalg as LA

def compute_norm():
    mat = np.matrix([[1,2],[3,4]])
    inv_mat = np.linalg.inv(mat)
    print inv_mat

def vector_norm():
    a = np.arange(9) - 4
    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
    b = a.reshape(3,3)
    b_t = np.transpose(b)
    b_new = np.dot(b_t,b) #b_new矩阵为b^t * b
    x = np.linalg.eigvals(b_new) #求b_new矩阵的特征值
    print x
    print LA.norm(b,1) #列范数
    print LA.norm(b,2) #谱范数,为x里最大值开平方
    print LA.norm(b,np.inf) #无穷范数,行范数
    print LA.norm(b,"fro") #F范数

vector_norm()
matrix_norm()
上一篇下一篇

猜你喜欢

热点阅读