How to sort each row from a two-dimensional MumPy array in Python

1 Answer

0 votes
import numpy as np

array2D = np.array([[3, 1, 2, 0], [9, 7, 8, 4], [6, 5, 4, 3]])

# Sort each row
sorted_array = np.sort(array2D, axis=1)

print(sorted_array)



'''
run:

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

'''

 



answered Mar 16 by avibootz
...