MACHINE LEARNING RECIPES
DATA CLEANING PYTHON
DATA MUNGING
PANDAS CHEATSHEET
ALL TAGS
# How to sort a 2D array by a column in numpy?

# How to sort a 2D array by a column in numpy?

This recipe helps you sort a 2D array by a column in numpy

How to sort a 2D array by a column. yes we can do this and for that we have to use the "sort" function available in the numpy library. In this if we want to sort 2D numpy array by 2nd column then we have to change the positions of all the rows based on the sorted values of the column (2nd column) with an column index for e.g 1 we can say.

```
import numpy as np
```

```
Sample_array = np.array([[100, 101, 500, 104], [201, 202, 203, 204], [301, 300, 600, 307]])
print("This is Sample 2D array :","\n", Sample_array)
```

This is Sample 2D array : [[100 101 500 104] [201 202 203 204] [301 300 600 307]]

```
Index = 2
Array_sort = Sample_array[Sample_array[:,Index].argsort()]
print("The original array is:","\n","\n", Sample_array, "\n")
print("The sorted array is:", "\n", "\n", Array_sort)
```

The original array is: [[100 101 500 104] [201 202 203 204] [301 300 600 307]] The sorted array is: [[201 202 203 204] [100 101 500 104] [301 300 600 307]]

Here we can see the array has been sorted according to the given Index number that we have passed in "Indexed" variable i.e 2. So we can see the 3rd column is been sorted now as before it was not.

In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.

In this data science project, you will work with German credit dataset using classification techniques like Decision Tree, Neural Networks etc to classify loan applications using R.

Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.

In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

There are different time series forecasting methods to forecast stock price, demand etc. In this machine learning project, you will learn to determine which forecasting method to be used when and how to apply with time series forecasting example.

Data Science Project in R -Build a machine learning algorithm to predict the future sale prices of homes.

In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.