[Python] Indexing An Array With Another Array with numpy

NumPy Reference: Indexing

def indexing():
    a = np.random.rand(5)
    print(a)  #[ 0.71899463  0.50556877  0.8397599   0.37655158  0.88041567]
    indices = np.array([1,1,2,3]) # access index of 1,1,2,3
    print(a[indices])  #[ 0.50556877  0.50556877  0.8397599   0.37655158]

if __name__ == "__main__":
    indexing()

 

posted @ 2017-12-18 21:32  Zhentiw  阅读(248)  评论(0编辑  收藏  举报