Python Slicing confusion with Numpy -


this question has answer here:

input:

import numpy np b=np.array([(1.5,2,3),(4,5,6)],dtype=float) b[[1,0,1,0]][:,[0,1,2,0]] 

output:

array([[ 4. ,  5. ,  6. ,  4. ],        [ 1.5,  2. ,  3. ,  1.5],        [ 4. ,  5. ,  6. ,  4. ],        [ 1.5,  2. ,  3. ,  1.5]]) 

i know b[:,[0,1,2,0]] , b[[1,0,1,0]], not know mechanism behind b[[1,0,1,0]][:,[0,1,2,0]]. clear explanation on it?

so many thanks!

you indexing lists, getting corresponding rows , columns (with repeats). indexing first list returns rows, , second columns. b[[1,0,1,0],[:0,1,2,0]] returns columns 0, 1, 2, 0 of rows 1, 0, 1, 0. 2 copies of each row, , copy of column 0 on rows.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -