Working with argmax

In higher dimensions torch.argmax method returns the list of indices of maximum values according to the specified axis. we can understand it with an example of how argmax() method works on 2 Dimensional tensors.

Example: [[1,10], [20,15]]

Two Dimensional tensor has only two axis-0,1 (Rows & Columns)

  • Along axis-0 The argmax method check for the maximum value in each column and returns the one index position of maximum value in each column. So in first column 20 is the maximum value and index value of it is 1 and in second column 15 is the maximum value and it’s Index is 1. so argmax method returns [1,1] as result.
  • Along the axis-1 The argmax method check for the maximum value in each row and returns the one index position of maximum value in each row. So in first row 10 is the maximum value and index value of it is 1 and in second row 20 is the maximum value it’s index position is 0. so argmax method returns [1,0] as result.

How Does torch.argmax Work for 4-Dimensions in Pytorch

In this article, we are going to discuss how does the torch.argmax work for 4-Dimensions with detailed examples.

Similar Reads

Torch.argmax() Method

Torch.argmax() method accepts a tensor and returns the indices of the maximum values of the input tensor across a specified dimension/axis. If the input tensor exists with multiple maximal values then the function will return the index of the first maximal element. Let’s look into the syntax of Torch.argmax() method along with its parameters....

Working with argmax

In higher dimensions torch.argmax method returns the list of indices of maximum values according to the specified axis. we can understand it with an example of how argmax() method works on 2 Dimensional tensors....

How Does torch.argmax Work for 4-Dimensions

If we didn’t set the keepdims=True in argmax() method for a 4-Dimensional input tensor with shape [1,2,3,4] and with axis=0, it will return an output tensor of shape [2,3,4]. Whereas for axis=1 the argmax() method returns a tensor with shape [1,3,4] which will be similar to another axis. so when we apply argmax method across any axis/dimension by default it will collapses that axis or dimension because its values are replaced by a single index....