import numpy as np
Fancy Index
x = np.array(list('ABCDEFG'))
x # array(['A', 'B', 'C', 'D', 'E', 'F', 'G'], dtype='<U1')
x[1] # 'B'
x[1:3] # array(['B', 'C'], dtype='<U1')
x[1:5] # array(['B', 'C', 'D', 'E'], dtype='<U1')
x[1:5:2] # 等步长 array(['B', 'D'], dtype='<U1')
[x[1], x[2], x[4]] # ['B', 'C', 'E']
ind = [1, 2, 4]
x[ind] # array(['B', 'C', 'E'], dtype='<U1')
ind = np.arange(1, 5).reshape(2, -1)
ind # array([[1, 2],
[3, 4]])
x[ind] # array([['B', 'C'],
['D', 'E']], dtype='<U1')
X = np.arange(16).reshape(4, -1)
X # array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]])
row = [0, 1, 3]
col = [1, 2, 3]
X[row, col] # array([ 1, 6, 15])
X[1:3, col] # array([[ 5, 6, 7],
[