2. Write a Python Numpy program to sort the given array along with the first axis, last axis and flattened array.
The output is:
a = [20,80],[60,40]
Expected Answer:
Initial array:
[[20 80]
[60 40]]
Sort the array along the first axis:
[[20 40]
[60 80]]
Sort the array along the last axis:
[[20 80]
[40 60]]
Sort the flattened array:
[20 40 60 80]
Sample Answer:
import numpy as np a = np.array([[20,80],[60,40]]) print("Initial array:") print(a) print("\nSort the array along the first axis:") print(np.sort(a, axis=0)) print("\nSort the array along the last axis:") print(np.sort(a)) print("\nSort the flattened array:") print(np.sort(a, axis=None))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)