Sorting arrays in NumPy by column

0 votes

How can I sort a numpy array with its nth column?

Consider this

a = array([[9, 2, 3],
           [4, 5, 6],
           [7, 0, 5]])

I want to sort rows of a by second column and get the output like this

array([[7, 0, 5],
       [9, 2, 3],
       [4, 5, 6]])
Aug 2, 2022 in Python by krishna
• 2,820 points
565 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
0 answers

Concatenate two numpy arrays in the 4th dimension

I got two numpy arrays in three ...READ MORE

Aug 1, 2022 in Python by krishna
• 2,820 points
469 views
0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
2,343 views
+1 vote
7 answers
0 votes
1 answer

Numpy: Multiplying large arrays with dtype=int8 is SLOW

Unfortunately, the "engine" behind the scenes is ...READ MORE

answered May 9, 2018 in Python by charlie_brown
• 7,720 points
1,278 views
0 votes
1 answer

Sorting a list of strings in Python

Use the sort function mylist.sort() READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
655 views
0 votes
1 answer

Numpy: Multiplying large arrays with dtype=int8 is SLOW

Unfortunately, as correctly underlined in the comments, the ...READ MORE

answered Sep 5, 2018 in Python by Priyaj
• 58,020 points
3,015 views
0 votes
1 answer

Python Pandas: selecting element in array column

pa.loc[row] selects the row with label row. pa.loc[row, ...READ MORE

answered May 13, 2019 in Python by SDeb
• 13,300 points
13,362 views
0 votes
1 answer

Sum of distances from a point to all other points

You can use cdist - In [1]: from scipy.spatial.distance import ...READ MORE

answered Jun 10, 2019 in Python by SDeb
• 13,300 points
1,704 views
0 votes
1 answer

NumPy Array Indexing

If you want to create a subarray ...READ MORE

answered Jul 26, 2019 in Python by SDeb
• 13,300 points
695 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP