a = np.arange(9).reshape((3,3)) 變換維度數組
np.max(a) 全局最大,也能夠加參數,找某個維度最大的dom
print(np.max(a,axis=0)) #每列最大ui
print(np.max(a,axis=1)) #每行最大spa
print(np.where(a==np.max(a))) ----》 (array([2], dtype=int64), array([2], dtype=int64)) 用where獲得最大值的索引,前面的array對應行數,後者對應列數。 若是array中有相同的最大值,where會將其位置所有給出排序
print(np.where(a==np.max(a,axis=0))) ---》(array([2, 2, 2], dtype=int64), array([0, 1, 2], dtype=int64))索引
np.argsort([1,2,3,5,9]) ---> [0,1,4,2,3] 返回排序的下標string
np.argmax([1,2,3,5,9]) 返回最大值得下標class
np.argmin([1,2,3,5,9]) 返回最小值得下標隨機數
np.bincount([1,2,3,5,9]) 返回每一個元素出現的次數 [0,1,1,1,0,1,0,0,0,1]numpy
np.argmax(np.bincount(array)) 返回出現次數最多的元素
a = np.array([[1, 5, 5, 2], [9, 6, 2, 8], [3, 7, 9, 1]]) print(np.sum(a, axis=0)) ---> [13,18,16,11]
a = np.array([[1, 5, 5, 2], [9, 6, 2, 8], [3, 7, 9, 1]]) print(np.sum(a, axis=1)) ----> [13,25,20].
np.dot() 點乘
array.T a.transpose() a的轉置,可是對一維數組不起做用
a.reshape(a.shape[0],1) 一維數組的轉置
a.reshape([-1]+a.shape[2:]) 高維數組降一維
numpy.random.choice(a, size=None, replace=True, p=None) 生成隨機數
np.random.choice(5, 3) --》 array([0, 3, 4])
np.sum([[0,1,2],[2,1,3]],axis=1)的結果就是:array([3,6])
b[b < 0] = 0 b矩陣中小於0 的元素設置爲0