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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -