In [1]:
import numpy as np

In [2]:
a = np.array([3, 4, 2, 0, 1])
print(a)


[3 4 2 0 1]

In [3]:
a_sort = np.sort(a)
print(a_sort)


[0 1 2 3 4]

In [4]:
print(a)


[3 4 2 0 1]

In [5]:
a_sort_reverse = np.sort(a)[::-1]
print(a_sort_reverse)


[4 3 2 1 0]

In [6]:
a_2d = np.array([[20, 3, 100], [1, 200, 30], [300, 10, 2]])
print(a_2d)


[[ 20   3 100]
 [  1 200  30]
 [300  10   2]]

In [7]:
a_2d_sort_col = np.sort(a_2d, axis=0)
print(a_2d_sort_col)


[[  1   3   2]
 [ 20  10  30]
 [300 200 100]]

In [8]:
a_2d_sort_row = np.sort(a_2d, axis=1)
print(a_2d_sort_row)


[[  3  20 100]
 [  1  30 200]
 [  2  10 300]]

In [9]:
a_2d_sort_row = np.sort(a_2d)
print(a_2d_sort_row)


[[  3  20 100]
 [  1  30 200]
 [  2  10 300]]

In [10]:
a_2d_sort_row = np.sort(a_2d, axis=-1)
print(a_2d_sort_row)


[[  3  20 100]
 [  1  30 200]
 [  2  10 300]]

In [11]:
a_2d_sort_col_reverse = np.sort(a_2d, axis=0)[::-1]
print(a_2d_sort_col_reverse)


[[300 200 100]
 [ 20  10  30]
 [  1   3   2]]

In [12]:
a_2d_sort_row_reverse = np.sort(a_2d, axis=1)[:, ::-1]
print(a_2d_sort_row_reverse)


[[100  20   3]
 [200  30   1]
 [300  10   2]]

In [13]:
print(a_2d)


[[ 20   3 100]
 [  1 200  30]
 [300  10   2]]

In [14]:
a_2d.sort()

print(a_2d)


[[  3  20 100]
 [  1  30 200]
 [  2  10 300]]

In [15]:
a_2d.sort(axis=0)

print(a_2d[::-1])


[[  3  30 300]
 [  2  20 200]
 [  1  10 100]]

In [16]:
a_2d = np.array([[20, 3, 100], [1, 200, 30], [300, 10, 2]])
print(a_2d)


[[ 20   3 100]
 [  1 200  30]
 [300  10   2]]

In [17]:
a_2d_sort_col_index = np.argsort(a_2d, axis=0)
print(a_2d_sort_col_index)


[[1 0 2]
 [0 2 1]
 [2 1 0]]

In [18]:
a_2d_sort_row_index = np.argsort(a_2d)
print(a_2d_sort_row_index)


[[1 0 2]
 [0 2 1]
 [2 1 0]]

In [19]:
print(a_2d)


[[ 20   3 100]
 [  1 200  30]
 [300  10   2]]

In [20]:
col_num = 1

In [21]:
print(a_2d[:, col_num])


[  3 200  10]

In [22]:
print(np.argsort(a_2d[:, col_num]))


[0 2 1]

In [23]:
a_2d_sort_col_num = a_2d[np.argsort(a_2d[:, col_num])]
print(a_2d_sort_col_num)


[[ 20   3 100]
 [300  10   2]
 [  1 200  30]]

In [24]:
print(np.argsort(a_2d[:, col_num])[::-1])


[1 2 0]

In [25]:
a_2d_sort_col_num_reverse = a_2d[np.argsort(a_2d[:, col_num])[::-1]]
print(a_2d_sort_col_num_reverse)


[[  1 200  30]
 [300  10   2]
 [ 20   3 100]]

In [26]:
print(a_2d)


[[ 20   3 100]
 [  1 200  30]
 [300  10   2]]

In [27]:
row_num = 1

In [28]:
print(a_2d[row_num])


[  1 200  30]

In [29]:
print(np.argsort(a_2d[row_num]))


[0 2 1]

In [30]:
a_2d_sort_row_num = a_2d[:, np.argsort(a_2d[row_num])]
print(a_2d_sort_row_num)


[[ 20 100   3]
 [  1  30 200]
 [300   2  10]]

In [31]:
print(np.argsort(a_2d[row_num])[::-1])


[1 2 0]

In [32]:
a_2d_sort_row_num_inverse = a_2d[:, np.argsort(a_2d[row_num])[::-1]]
print(a_2d_sort_row_num_inverse)


[[  3 100  20]
 [200  30   1]
 [ 10   2 300]]