【向量范数】
向量由于既有大小又有方向,所以不能直接比较大小。
向量范数通过将向量转化为实数,然后进行向量的大小比较。
所以,向量范数是用于度量“向量大小”的量。
设向量
,则有:
● 向量的
范数:![\left \| X \right \|_p=\sqrt[p]{\sum\limits_{i=1} \limits^{n}\left | x_i \right |^p}](https://1000bd.com/contentImg/2024/04/06/6f611849e6aeee46.png)
● 向量的
范数:
- def vector_L1_norm(x):
- return sum(abs(i) for i in x)
- x=[1,2,3]
- vector_L1_norm(x)
● 向量的
范数:
- import math
- def vector_L2_norm(x):
- return math.sqrt(sum(pow(i,2) for i in x))
- x=[1,2,3]
- vector_L2_norm(x)
● 向量的
范数:
- def vector_Linf_norm(x):
- return max(abs(i) for i in x)
- x=[1,2,3]
- vector_Linf_norm(x)
【参考文献】
https://www.cnblogs.com/BlueBlueSea/p/10630262.html
https://www.python100.com/html/RB1W976G4PM3.html
https://devpress.csdn.net/python/62fbc943c677032930800c06.html