Taking the maximum values of each row in a tensor [PyTorch]
Suppose I have a tensor of the form

[[-5, 0, -1],
 [3, 100, 87],
 [17, -34, 2],
 [45, 1, 25]]


I want to find the maximum value in each row and return a rank 1 tensor as follows:

[0,
 100,
 17,
 45]


How would I do this in PyTorch?

You can use the torch.max() function. So you can do something like

x = torch.Tensor([[-5, 0, -1],
                  [3, 100, 87],
                  [17, -34, 2],
                  [45, 1, 25]])
out, inds = torch.max(x,dim=1)


and this will return the maximum values across each row (dimension 1). It will return max values with their indices. 
