3-17Pytorch与线性代数运算

3-17Pytorch与线性代数运算_第1张图片

二范数:欧氏距离
核范数:低秩问题的求解
计算机技术中有一种特点,图像有一种区域性,反应到数据上就是有相关性
范数作用:定义loss,参数约束

import torch
a = torch.rand(1,1)
b = torch.rand(1,1)

print(a,b)

print(torch.dist(a,b,p = 0))
print(torch.dist(a,b,p = 1))
print(torch.dist(a,b,p = 2))
print(torch.dist(a,b,p = 3))
print('-------------------------------------------------')
print(torch.norm(a))
print(torch.norm(a,p = 0))
print(torch.norm(a,p = 1))
print(torch.norm(a,p = 2))
print(torch.norm(a,p = 3))
#计算核范数
print('核范数:',torch.norm(a,p = 'fro'))
tensor([[0.9197]]) tensor([[0.8488]])
tensor(1.)
tensor(0.0708)
tensor(0.0708)
tensor(0.0708)
-------------------------------------------------
tensor(0.9197)
tensor(1.)
tensor(0.9197)
tensor(0.9197)
tensor(0.9197)
核范数: tensor(0.9197)

你可能感兴趣的:(pytorch学习)