I didn't understand it in the PyTorch documentation, so I'll leave it. Code from Documentation
a = torch.randn(1, 3)
a
tensor([[ 0.6763, 0.7445, -2.2369]])
torch.max(a)
tensor(0.7445)
Yeah, it returns the element with the maximum value of the simplest one-dimensional array
a = torch.randn(4, 4)
a
tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
[ 1.1949, -1.1127, -2.2379, -0.6702],
[ 1.5717, -0.9207, 0.1297, -1.8768],
[-0.6172, 1.0036, -0.6060, -0.2432]])
torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
I didn't really understand the second argument of this It was the axis of numpy. So personally
a = torch.randn(4, 4)
a
tensor([[-1.2360, -0.2942, -0.1222, 0.8475],
[ 1.1949, -1.1127, -2.2379, -0.6702],
[ 1.5717, -0.9207, 0.1297, -1.8768],
[-0.6172, 1.0036, -0.6060, -0.2432]])
axis = 1
torch.max(a, axis)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))
It is easier to understand.
torch.max(a, axis)Such usage is used in classification.
By the way, although it is for myself, axis is the axis! (```axis = 0: col, axis = 1: row```)
# in conclusion
I'm still swayed by libraries and math, so I want to be able to use it well as soon as possible.
Recommended Posts