Imagine, I have a 2D NumPy array X with 100 columns and 100 rows. Then, how can I extract the following rows and column using indexing?
rows= 1, 5, 15, 16 to 35, 45, 55 to 75
columns = 1, 2, 10 to 30, 42, 50
I know in MATLAB, we can do this using
X([1,5,15,16:35,45,55:75],[1,2,10:30,42,50]).
How can we do this in Python?
numpyhandles the block versussub2indcases differently.np.ix_(list1, list2)to see the kinds arrays needed to index a block. To understandarr[ idx1, idx2]innumpyyou have to understand howidx1broadcasts withidx2. These are the same rules as used when adding two arrays.