将numpy作为np导入
gens = np.array([2, 1, 2, 1, 0, 1, 2, 1, 2])
p = [0,1]
gens
匹配
p
.
result = [[4],[2,3,5,7],[0,2,6,8]]
#[[where matched 0], [where matched 1], [the rest]]
--
indx = gens.argsort()
res = np.searchsorted(gens[indx], [0])
gens[res] #gives 4, which is the position of 0
但我试着
indx = gens.argsort()
res = np.searchsorted(gens[indx], [1])
gens[res] #gives 1, which is the position of the first 1.
所以: