PyTorch笔记08----统计属性
记录了PyTorch一些常见统计属性.
常见统计属性: - norm 范数 - mean sum - prod 累乘 - min max argmin argmax 最小/大值的位置 - kthvalue topk
norm
不是normalize正则化 矩阵范数与向量范数有区别的
norm-p p范数 a = torch.full([8], 1)
b = a.review(2, 4)
c = a.review(2, 2, 2)
a.norm(1), b.norm(1), c.norm(1)
#tensor(8.), tensor(8.), tensor(8.)
a.norm(2), b.norm(2), c.norm(2)
#tensor(2.8284), tensor(2.8284), tensor(2.8284)
b.norm(1, dim = 0)
#tensor([4., 4.])
c.norm(1, dim = 0)
#tensor([[2, 2],
[2, 2]])
mean / sum / min / max / prod / argmax / argmin
a = torch.arange(8).view(2, 4).float() |
dim / keepdim
a = torch.rand(4, 10) |
top-k / k-th
- top-k 返回最大的k个数和其索引
a = torch.randn(4, 10) |
- kthvalue
a.kthvalue(8, dim = 1) |
compare
>, >=, <, <=, !=, ==
a > 0
#tensor([[0, 0, 0, 1, ...],
[0, 0, 0, 0, ...],
[0, 1, 1, 0, ...],
[0, 0, 0, 0, ...]])
torch.gt(a, 0) #结果同上
b = rand(2, 2)
torch.eq(b, b)
#tensor([[1, 1],
[1, 1]])
torch.equal(b, b)
#True