12 ,np 數學函數 :行列最大值索引,行列排序

1 ,行列最大值 :nd01.argmax(axis=0),nd01.argmax(axis=1)

  1. 代碼 :
if __name__ == '__main__':
    # 造數據 ( 利用了正弦函數 )
    nd01 = (np.sin(np.arange(20))).reshape(5,4)
    # 每一列的最大值,每一行的最大值
    res01 = nd01.argmax(axis=0)
    res02 = nd01.argmax(axis=1)
    print(nd01)
    print(res01)
    print(res02)
==============================================================
[[ 0.          0.84147098  0.90929743  0.14112001]
 [-0.7568025  -0.95892427 -0.2794155   0.6569866 ]
 [ 0.98935825  0.41211849 -0.54402111 -0.99999021]
 [-0.53657292  0.42016704  0.99060736  0.65028784]
 [-0.28790332 -0.96139749 -0.75098725  0.14987721]]
[2 0 3 1]
[2 3 0 2 3]

2 ,行列排序 : np.sort(nd01,axis=0)

  1. 代碼 :
if __name__ == '__main__':
    nd01 = np.array([[2,1,3,4],
                     [1,2,4,3]])
    nd02 = np.sort(nd01,axis=0)
    nd03 = np.sort(nd01,axis=1)
    print(nd01)
    print(nd02)
    print(nd03)
==============================
[[2 1 3 4]
 [1 2 4 3]]
================
[[1 1 3 3]
 [2 2 4 4]]
================
[[1 2 3 4]
 [1 2 3 4]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章