import itertools
# 数组元素的排列与组合
print list(itertools.permutations([1,2,3],2)) #排列
print list(itertools.combinations([1,2,3],2)) # 组合
"""
sort 2D numpy array ordered by first column (x) , then by second column (y) if and only if x is the same.
data = np.array([[0,0,1],
[0,1,2],
[0,2,1],
[1,1,3],
[1,0,1],
[1,2,2]])
[[0 0 1]
np.lexsort((data[:,1],data[:,0]))
output: [0 1 2]
[0 2 1]
[1 1 3]
[1 0 1]
[1 2 2]]
"""
# 实现对二维数组的排序,排序规则为以前俩列为准,第一列优先,第二列其次
import numpy as np
data = np.array([[0,0,1],
[0,1,2],
[0,2,1],
[1,1,3],
[1,0,1],
[1,2,2]])
ind = np.lexsort((data[:,1],data[:,0]))
print data[ind]
# 以数组 a 的从小到大的顺序为基准,对数组 b 进行重排序,并返回排序结果的索引数组
a = np.array([0,1,3,2,6,4,5])
b = np.array([0,1,2,3,4,5,6])
index = np.lexsort((b, a))