NumPy Reference: Indexing
- Integer array indexing: Select array elements with another array
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()