- 只有array有资格使用布尔条件判断来进行索引
x = [2, 10, 2, 1, 5, 11, 9, 1, 1, 9, 1, 3, 1, 2]
x = np.array(x)
x = np.hstack([x[x==i] for i in range(10)])
print x
输出
[1 1 1 1 1 2 2 2 3 5 9 9]
x = [2, 10, 2, 1, 5, 11, 9, 1, 1, 9, 1, 3, 1, 2]
x = np.array(x)
x = np.hstack([x[x==i] for i in range(10)])
print x
输出
[1 1 1 1 1 2 2 2 3 5 9 9]