1. np.argsort 数据排序 对应的下标
import numpy as np
scores = np.array([0.9, 0.5, 0.3, 0.6])
print(scores.argsort()) # 从小到大排序 对应原数的index
print(scores.argsort()[::-1]) # 逆序 从大到小
[2 1 3 0]
[0 3 1 2]
2. np.tile 矩阵 平移复制
import numpy as np
a = np.array([0, 1, 2])
print(a) # [0 1 2]
print(a.shape) # (3,)
a1 = np.tile(a, 2)
print(a1) # [0 1 2 0 1 2]
print(a1.shape) # (6,)
a2 = np.tile(a, (2, 3))
print(a2)
print(a2.shape) # (2, 9)
# [[0 1 2 0 1 2 0 1 2]
# [0 1 2 0 1 2 0 1 2]]
网友评论