The argmax operation can be performed quickly in numpy using the argmax
function. The argmax
function returns the indices of the maximum values along an axis.
Here is an example:
import numpy as np a = np.array([[5, 2, 3], [7, 1, 4], [0, 8, 6]]) # Find the index of the maximum value along axis 0 max_idx = np.argmax(a, axis=0) print(max_idx) # Output: [1 2 2] # Find the index of the maximum value along axis 1 max_idx = np.argmax(a, axis=1) print(max_idx) # Output: [0 0 1]
In this example, we have a 3x3 numpy array a
and we are finding the index of the maximum value along axis 0 and axis 1 using the argmax
function. We get the output [1 2 2]
when we find the maximum value along axis 0, which means that the maximum values are located at index 1 in the first column, index 2 in the second column, and index 2 in the third column. Similarly, we get the output [0 0 1]
when we find the maximum value along axis 1, which means that the maximum values are located at index 0 in the first row, index 0 in the second row, and index 1 in the third row.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-20 11:00:00 +0000
Seen: 13 times
Last updated: Jan 09 '23
How can I set up Gunicorn with a Django Project?
Looking for a Python Module that finds Tags for a Text describing its Content
Need a Function in Python to remove entries less than 2 digits from an Array
How can I convert a Document in Python?
How can I program a Loop in Python?
How can I enable Python Code Highlighting in Askbot?