The index uses numpy

index

argmin-- minimum index, argmax-- maximum index

import numpy as np
x = np.random.normal(0,1,size=1000000)
np.min(x)
-4.736102442527367
np.argmin(x)
258131
x[258131]
-4.736102442527367
np.max(x)
4.788201736638607
np.argmax(x)
24635
x[24635]
4.788201736638607

Sorting and indexing

x = np.arange(16)
x
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15])

shuffle-- random array upset

np.random.shuffle(x)
x
array([14, 10,  7,  8, 11,  0, 13,  5,  2,  3,  4, 15, 12,  9,  6,  1])

Multi-dimensional array sort

x = np.random.randint(0,10,size=(4,4))
x
array([[7, 8, 0, 9],
       [5, 1, 8, 2],
       [3, 4, 0, 3],
       [6, 0, 3, 0]])
np.sort(x)#这里存在axis参数,与聚合函数中的原理一致,这里默认按行排序
array([[0, 7, 8, 9],
       [1, 2, 5, 8],
       [0, 3, 3, 4],
       [0, 0, 3, 6]])

Sort by index

x = np.arange(1,10)
np.random.shuffle(x)
x
array([4, 9, 7, 2, 8, 1, 3, 6, 5])
np.argsort(x)#这里是按照索引方式排序,3指的是原数组中最小值的索引为3
array([5, 3, 6, 0, 8, 7, 2, 4, 1], dtype=int64)

paritition-- quick sort

Pass a calibration value (there is an incoming index) to return to a border point calibration point division, while smaller than the fixed-point mark, the other side is larger than the fixed-point mark

p = np.array([1,2,3,4,5,6,7,44,9,4])
p
array([ 1,  2,  3,  4,  5,  6,  7, 44,  9,  4])
np.partition(p,7)
array([ 2,  1,  3,  4,  4,  5,  6,  7,  9, 44])

Guess you like

Origin www.cnblogs.com/Missv4you/p/12032006.html
Recommended