Get max value and its index in numpy array

batuman

I have this torch array.

       tensor([[8.22266e-01, 1.34659e-03, 9.85146e-04, 8.11100e-04],
    [9.35547e-01, 1.22261e-03, 8.70228e-04, 1.25122e-03],
    [9.48730e-01, 1.21975e-03, 9.28402e-04, 8.44955e-04],
    [7.97363e-01, 9.16004e-04, 9.16004e-04, 8.53539e-04],
    [9.26270e-01, 7.69138e-04, 8.47816e-04, 1.12724e-03],
    [9.43848e-01, 7.44820e-04, 8.53539e-04, 8.60691e-04],
    [7.89062e-01, 6.50406e-04, 9.23634e-04, 8.44479e-04],
    [9.29688e-01, 7.02858e-04, 7.60078e-04, 1.19591e-03],
    [9.47266e-01, 5.88894e-04, 8.36849e-04, 9.37462e-04],
    [8.27637e-01, 1.92642e-03, 1.73283e-03, 2.53105e-03],
    [9.22363e-01, 2.23160e-03, 1.37615e-03, 2.46811e-03],
    [9.31641e-01, 1.92928e-03, 1.49632e-03, 2.53296e-03],
    [8.25684e-01, 1.89209e-03, 1.70994e-03, 2.39944e-03],
    [9.21875e-01, 1.90926e-03, 1.28174e-03, 2.44904e-03],
    [9.25781e-01, 1.65272e-03, 1.45912e-03, 2.44141e-03],
    [8.39844e-01, 3.17955e-03, 4.02832e-03, 5.22614e-03],
    [9.17480e-01, 3.13759e-03, 3.37982e-03, 4.72260e-03],
    [9.37012e-01, 2.63405e-03, 3.57056e-03, 4.70734e-03]], device='cuda:0',                                                                              dtype=torch.float16)

I like to get its max value and index for each row in Torch is

conf, j = x[:, 5:].max(1, keepdim=True)

How can I implement in numpy if I have 2D numpy array?

Shai

You are looking for numpy.argmax

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Initialise a NumPy array based on its index

Java - How to get item index from an array with its value?

How to get the index and max value of an array in one shot?

Replace value in an array by its index in a list

Numpy sum elements in array based on its value

How to get max value at the same index in array of arrays?

Get the index of a Numpy Array

Iterating numpy array to find max value within subarray leaving the row index

Python Numpy Determine array index which contains overall max/min value

How to get nth max correlation coefficient and its index by using numpy?

get neighbors of a max value in 2D numpy array

numpy 2d: How to get the index of the max element in the first column for only the allowed value in the second column

How can I index of each occurrence of a max value along a given axis of a numpy array?

Get the value of the array index

How to find max value in a numpy array column?

Find the index corresponding to the max value of a numpy array

max value from specified column in numpy array

How to find index of max array value?

How to get the index of non-zero value in a numpy array quickly?

How to find corresponding max value in numpy array

how can I get the index of the max value in an array?

Display Array item using its Index value

Variable in array's index not changing the its value

Replacing numpy array with max value

Finding the index of max value of columns in numpy array but removing the previous max

How to get index from value in 2D Numpy array

Swap min and max value in NumPy array

Numpy - Determine nearly equivalent floats before finding max value and index in 1D array

Numpy method to get max value of numpy array for multiple ranges