In [1]:
import numpy as np
In [2]:
a = np.array([3, 4, 2, 0, 1])
print(a)
In [3]:
a_sort = np.sort(a)
print(a_sort)
In [4]:
print(a)
In [5]:
a_sort_reverse = np.sort(a)[::-1]
print(a_sort_reverse)
In [6]:
a_2d = np.array([[20, 3, 100], [1, 200, 30], [300, 10, 2]])
print(a_2d)
In [7]:
a_2d_sort_col = np.sort(a_2d, axis=0)
print(a_2d_sort_col)
In [8]:
a_2d_sort_row = np.sort(a_2d, axis=1)
print(a_2d_sort_row)
In [9]:
a_2d_sort_row = np.sort(a_2d)
print(a_2d_sort_row)
In [10]:
a_2d_sort_row = np.sort(a_2d, axis=-1)
print(a_2d_sort_row)
In [11]:
a_2d_sort_col_reverse = np.sort(a_2d, axis=0)[::-1]
print(a_2d_sort_col_reverse)
In [12]:
a_2d_sort_row_reverse = np.sort(a_2d, axis=1)[:, ::-1]
print(a_2d_sort_row_reverse)
In [13]:
print(a_2d)
In [14]:
a_2d.sort()
print(a_2d)
In [15]:
a_2d.sort(axis=0)
print(a_2d[::-1])
In [16]:
a_2d = np.array([[20, 3, 100], [1, 200, 30], [300, 10, 2]])
print(a_2d)
In [17]:
a_2d_sort_col_index = np.argsort(a_2d, axis=0)
print(a_2d_sort_col_index)
In [18]:
a_2d_sort_row_index = np.argsort(a_2d)
print(a_2d_sort_row_index)
In [19]:
print(a_2d)
In [20]:
col_num = 1
In [21]:
print(a_2d[:, col_num])
In [22]:
print(np.argsort(a_2d[:, col_num]))
In [23]:
a_2d_sort_col_num = a_2d[np.argsort(a_2d[:, col_num])]
print(a_2d_sort_col_num)
In [24]:
print(np.argsort(a_2d[:, col_num])[::-1])
In [25]:
a_2d_sort_col_num_reverse = a_2d[np.argsort(a_2d[:, col_num])[::-1]]
print(a_2d_sort_col_num_reverse)
In [26]:
print(a_2d)
In [27]:
row_num = 1
In [28]:
print(a_2d[row_num])
In [29]:
print(np.argsort(a_2d[row_num]))
In [30]:
a_2d_sort_row_num = a_2d[:, np.argsort(a_2d[row_num])]
print(a_2d_sort_row_num)
In [31]:
print(np.argsort(a_2d[row_num])[::-1])
In [32]:
a_2d_sort_row_num_inverse = a_2d[:, np.argsort(a_2d[row_num])[::-1]]
print(a_2d_sort_row_num_inverse)