1>>> a = np.array([[1,4],[3,1]])
2>>> np.sort(a) # sort along the last axis
3array([[1, 4],
4 [1, 3]])
5>>> np.sort(a, axis=None) # sort the flattened array
6array([1, 1, 3, 4])
7>>> np.sort(a, axis=0) # sort along the first axis
8array([[1, 1],
9 [3, 4]])
10
1import numpy as np
2
3arr = np.array(['banana', 'cherry', 'apple'])
4
5print(np.sort(arr))
1import numpy as np
2#original 2-dimentional array
3nnl_array = np.array([[1,5,3], [6,5,7]])
4print ("original array", "\n", nnl_array)
5#axis=none
6a_nnl_array = np.sort(nnl_array, axis=None)
7print("axis=none", "\n", a_nnl_array)
8#axis=-1
9b_nnl_array = np.sort(nnl_array, axis=-1)
10print("axis=-1", "\n", b_nnl_array)
11#axis=0
12c_nnl_array = np.sort(nnl_array, axis=0)
13print("axis=0", "\n", c_nnl_array)
14#axis=1
15d_nnl_array = np.sort(nnl_array, axis=1)
16print("axis=1", "\n", d_nnl_array)