Skip to content
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS
Close
Beyond Knowledge Innovation

Beyond Knowledge Innovation

Where Data Unveils Possibilities

  • Home
  • AI & ML Insights
  • Machine Learning
    • Supervised Learning
      • Introduction
      • Regression
      • Classification
    • Unsupervised Learning
      • Introduction
      • Clustering
      • Association
      • Dimensionality Reduction
    • Reinforcement Learning
    • Generative AI
  • Knowledge Base
    • Introduction To Python
    • Introduction To Data
    • Introduction to EDA
  • References
HomeKnowledge BasePythonNumPy function argmax
Python

NumPy function argmax

March 10, 2024March 10, 2024CEO 368 views

np.argmax is a NumPy function that returns the indices of the maximum values along a specified axis in an array. If the input array is multi-dimensional, you can specify the axis along which the maximum values are computed.

Here’s a simple example:

import numpy as np

arr = np.array([1, 5, 2, 8, 3])

# Get the index of the maximum value in the array
index_of_max_value = np.argmax(arr)

print("Array:", arr)
print("Index of Maximum Value:", index_of_max_value)
print("Maximum Value:", arr[index_of_max_value])

Output:

Array: [1 5 2 8 3]
Index of Maximum Value: 3
Maximum Value: 8

In this example, np.argmax(arr) returns the index (position) of the maximum value in the array arr. The maximum value is 8, and it is at index 3 (0-indexed).

You can also use np.argmax with multi-dimensional arrays and specify the axis along which the maximum values should be computed. For example:

import numpy as np

arr_2d = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

# Get the indices of the maximum values along each column (axis=0)
indices_of_max_values = np.argmax(arr_2d, axis=0)

print("2D Array:")
print(arr_2d)
print("Indices of Maximum Values along Each Column:", indices_of_max_values)

Output:

2D Array:
[[1 2 3]
 [4 5 6]
 [7 8 9]]
Indices of Maximum Values along Each Column: [2 2 2]

In this 2D array example, np.argmax(arr_2d, axis=0) returns the indices of the maximum values along each column (axis=0). The result is an array [2, 2, 2], indicating that the maximum values in each column are found in the third row.

argmax, indices, numpy

Post navigation

Previous Post
Previous post: Parameter cv in GridSearchCV
Next Post
Next post: What is Logistic Regression?

You Might Also Like

No image
NumPy function argsort
March 10, 2024 Comments Off on NumPy function argsort
No image
How-to: cap/clip outliers in a column
February 6, 2024 Comments Off on How-to: cap/clip outliers in a column
No image
How to Save Your Python Objects in…
January 19, 2024 Comments Off on How to Save Your Python Objects in Google Colab
No image
NumPy View array vs. Copy array
January 19, 2024 Comments Off on NumPy View array vs. Copy array
No image
What is NumPy?
January 18, 2024 Comments Off on What is NumPy?
  • Recent
  • Popular
  • Random
  • No image
    1 year ago Low-Rank Factorization
  • No image
    1 year ago Perturbation Test for a Regression Model
  • No image
    1 year ago Calibration Curve for Classification Models
  • No image
    March 15, 20240Single linkage hierarchical clustering
  • No image
    April 17, 20240XGBoost (eXtreme Gradient Boosting)
  • No image
    April 17, 20240Gradient Boosting
  • No image
    April 24, 2024RandomizedSearchCV vs GridSearchCV
  • No image
    March 17, 2024t-distributed Stochastic Neighbor Embedding (t-SNE)
  • No image
    August 12, 2024Correlation Coefficient
  • Implementation (55)
    • EDA (4)
    • Neural Networks (10)
    • Supervised Learning (26)
      • Classification (17)
      • Linear Regression (8)
    • Unsupervised Learning (11)
      • Clustering (8)
      • Dimensionality Reduction (3)
  • Knowledge Base (44)
    • Python (27)
    • Statistics (6)
April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Oct    

We are on

FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS

Subscribe

© 2026 Beyond Knowledge Innovation
FacebookTwitterLinkedinYouTubeGitHubSubscribeEmailRSS