Q:

Write a NumPy program to sort a given array by row and column in ascending order

0

Write a NumPy program to sort a given array by row and column in ascending order.

All Answers

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

import numpy as np  
nums = np.array([[5.54, 3.38, 7.99],
              [3.54, 4.38, 6.99],
              [1.54, 2.39, 9.29]])
print("Original array:")
print(nums)
print("\nSort the said array by row in ascending order:")
print(np.sort(nums))
print("\nSort the said array by column in ascending order:")
print(np.sort(nums, axis=0))

Sample Output:

Original array:
[[5.54 3.38 7.99]
 [3.54 4.38 6.99]
 [1.54 2.39 9.29]]

Sort the said array by row in ascending order:
[[3.38 5.54 7.99]
 [3.54 4.38 6.99]
 [1.54 2.39 9.29]]

Sort the said array by column in ascending order:
[[1.54 2.39 6.99]
 [3.54 3.38 7.99]
 [5.54 4.38 9.29]]

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