背景
实现一维numpy数组
a = array([1,0,3])
转换为2维的 1-hot数组
b = array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])
python实现示例代码...import numpy as np
if __name__ == '__main__':
ind = np.array([1, 0, 3])
x = np.zeros((ind.size...]
[0. 0. 0. 1.]]
fancy indexing介绍
fancy indexing:传递索引数组来一次返回多个数组元素。...索引为一维数组
import numpy as np
if __name__ == '__main__':
x = np.array([51, 92, 14, 71, 60, 20, 82, 86,...74, 74])
ind = [3, 4, 5]
print(x[ind])
结果展示:
[71 60 20]
索引为二维数组
import numpy as np
if __name