Q:

Write a NumPy program to sort an given array by the nth column

0

Write a NumPy program to sort an given array by the nth column.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
print("Original array:\n")
nums = np.random.randint(0,10,(3,3))
print(nums)
print("\nSort the said array by the nth column: ")
print(nums[nums[:,1].argsort()])

Sample Output:

Original array:

[[1 5 0]
 [3 2 5]
 [8 7 6]]

Sort the said array by the nth column: 
[[3 2 5]
 [1 5 0]
 [8 7 6]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now