统计属性函数(含.max(1)用法)
statistics
1.norm
2.mean sum
3.prod
4.max,min,argmin,argmax
5.kthvalue,topk
>>> import torch
>>> a=torch.randn(4,10)
>>> print(a)
tensor([[ 0.1002, -1.6265, 1.4466, 2.2931, -1.0597, 1.1463, -0.9219, -1.3728,
0.5217, -0.8573],
[ 1.5552, 2.1135, 0.8474, -0.2791, -1.3415, 1.9675, -0.9590, 0.3891,
-0.3999, 0.6661],
[ 2.6432, -0.3486, -0.0697, 0.4470, -1.6899, 0.2445, -1.0605, -1.2437,
1.2988, -0.2264],
[-0.8405, -1.5584, -0.3764, -1.1917, 0.4766, -0.6043, 1.0400, 0.6237,
0.9253, 1.1696]])
>>> print(a.min())# 整体最小
tensor(-1.6899)
>>> print(a.max())#整体最大
tensor(2.6432)
>>> print(a.mean())
tensor(0.0972)
>>> print(a.prod())
tensor(4.1418e-05)
>>> print(a.std())
tensor(1.1816)
>>> print(a.sum())
tensor(3.8876)
>>> print(a.argmax(dim=0))
tensor([2, 1, 0, 0, 3, 1, 3, 3, 2, 3])
>>> print(a.argsort())
tensor([[1, 7, 4, 6, 9, 0, 8, 5, 2, 3],
[4, 6, 8, 3, 7, 9, 2, 0, 5, 1],
[4, 7, 6, 1, 9, 2, 5, 3, 8, 0],
[1, 3, 0, 5, 2, 4, 7, 8, 6, 9]])
>>> print(a.argmin(dim=1))
tensor([1, 4, 4, 1])
>>> print(a.max(1))
torch.return_types.max(
values=tensor([2.2931, 2.1135, 2.6432, 1.1696]),
indices=tensor([3, 1, 0, 9]))
>>> print(a)
tensor([[ 0.1002, -1.6265, 1.4466, 2.2931, -1.0597, 1.1463, -0.9219, -1.3728,
0.5217, -0.8573],
[ 1.5552, 2.1135, 0.8474, -0.2791, -1.3415, 1.9675, -0.9590, 0.3891,
-0.3999, 0.6661],
[ 2.6432, -0.3486, -0.0697, 0.4470, -1.6899, 0.2445, -1.0605, -1.2437,
1.2988, -0.2264],
[-0.8405, -1.5584, -0.3764, -1.1917, 0.4766, -0.6043, 1.0400, 0.6237,
0.9253, 1.1696]])
a.max(1)输出了每行最大,排列成一维数组,同时输出最大值在每行中的序号,