Q:

Write a NumPy program to sort an along the first, last axis of an array

0

Write a NumPy program to sort an along the first, last axis of an array.
Sample array: [[2,5],[4,4]]

All Answers

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

import numpy as np
a = np.array([[4, 6],[2, 1]])
print("Original array: ")
print(a)
print("Sort along the first axis: ")
x = np.sort(a, axis=0)
print(x)
print("Sort along the last axis: ")
y = np.sort(x, axis=1)
print(y)

Sample Output:

Expected Output:
Original array:                                                                        
[[4 6]                                                                                 
 [2 1]]                                                                                
Sort along the first axis:                                                             
[[2 1]                                                                                 
 [4 6]]                                                                                
Sort along the last axis:                                                              
[[1 2]                                                                                 
 [4 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