numpy中的np.where使用的小细节
import numpy as np
label = np.array([[0,1,0,1,1],[1,1,0,1,1],[0,0,0,1,1]])
pos_index = np.where(label[0] == 1)
运行上面代码,返回的pos_index是一个包含array数组的元组,如下图所示:
要先获得numpy类型数组,必须在pos_index后加索引:
import numpy as np
label = np.array([[0,1,0,1,1],[1,1,0,1,1],[0,0,0,1,1]])
pos_index = np.where(label[0] == 1)[0]
运行后结果如下: