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 argsort
Python

NumPy function argsort

March 10, 2024March 10, 2024CEO 411 views

np.argsort is a NumPy function that returns the indices that would sort an array along a specified axis. It performs an indirect sort on the input array and returns an array of indices that represent the sorted order of the elements. The returned indices can be used to construct a sorted version of the input array.

The values in the sorted indices array returned by np.argsort represent the indices of the elements in the original array that would arrange the elements in ascending order. In other words, each value in the sorted indices array indicates the position of an element in the sorted order.

Let’s break down the example for better understanding:

import numpy as np

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

# Get the indices that would sort the array
sorted_indices = np.argsort(arr)

print("Original array:", arr)
print("Sorted indices:", sorted_indices)
print("Sorted array:", arr[sorted_indices])

It will return:

  1. Original array: [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
  2. Sorted indices: [1, 3, 6, 0, 9, 4, 8, 10, 2, 7, 5]
  3. Sorted array: [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9]

Here’s the breakdown:

  • The original array has values [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5].
  • The sorted indices array indicates the indices of the elements in the original array if it were sorted in ascending order. For example, the smallest element in the original array is at index 1 (arr[1]), the second smallest is at index 3 (arr[3]), and so on.
  • The sorted array is constructed by using the sorted indices to rearrange the elements of the original array.

argsort, indices, numpy

Post navigation

Previous Post
Previous post: Post-pruning Decision Tree with Cost Complexity Parameter ccp_alpha
Next Post
Next post: Parameter cv in GridSearchCV

You Might Also Like

No image
NumPy function argmax
March 10, 2024 Comments Off on NumPy function argmax
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
    2 years ago Low-Rank Factorization
  • No image
    2 years ago Perturbation Test for a Regression Model
  • No image
    2 years 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
    May 5, 2024Multi-Layer Perceptron (MLP) in artificial neural network
  • No image
    January 30, 2024Univariate Analysis in EDA
  • No image
    January 16, 2024How to create a smaller dataset for…
  • 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