numpy(五)

排序:

 x=np.array([2,5,6,2,3,5])

np.sort(x)  不改变原数组

x.sort() 改变原数组

i=np.argsort(x) 返回排序好的索引值

x[i] 使用花哨索引返回排序好的数组

x=np.random.randint(0,10,(4,6))

np.sort(x,axis=0) 对每一列排序

np.sort(x,axis=1) 对每一行排序   会丢失原先行或列之间的关系

部分排序:

x=np.array([7,2,3,1,6,5,4])

np.partition(x,3) 

结果左边第3小及更小的值 按顺序排列,右边则是任意顺序的其他值

np.partitions(x,2,axis=1)  找出每行的第三小以前的值