Integer array indexing python -


import numpy np  = np.array([[1,2], [3, 4], [5, 6]])  print(a[[0, 1, 2], [0, 1, 0]])  # prints "[1 4 5]"  print(a[[0, 0], [1, 1]])  # prints "[2 2]" 

i don't understand why results [1 4 5] , [2 2]

because you're slicing array indexes

a[[0, 1, 2], [0, 1, 0]] equivalent to

a[0, 0]  # 1 a[1, 1]  # 4 a[2, 0]  # 5 

whereas a[[0, 0], [1, 1]] equivalent twice a[0, 1]

more numpy indexing here


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -