指数
argmin--最小インデックス、argmax--最大インデックス
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
ソートとインデックス作成
x = np.arange(16)
x
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
shuffle--ランダム配列の動揺
np.random.shuffle(x)
x
array([14, 10, 7, 8, 11, 0, 13, 5, 2, 3, 4, 15, 12, 9, 6, 1])
多次元配列のソート
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]])
インデックスで並べ替え
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--
固定小数点マークよりも小さく、他方の側は、固定小数点マークよりも大きいが、境界点校正点分割に戻り(着信インデックスがある)較正値を渡します
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])