Skip to content Skip to sidebar Skip to footer

How To Slice A 2d Array Non-consecutively In Python

My friend A is back and she now looks like A = np.array([ [0,1,1,1,0,0,0,0], [1,0,0,1,0,0,0,0], [1,0,0,1,0,0,0,0], [1,1,1,0,0,0,0,0], [0,0,0,1,0,1,0,0], [0

Solution 1:

You can use np.ix_:

A[np.ix_((1,3,7),(2,3,6))]
#array([[0, 1, 0],
#       [1, 0, 0],
#       [0, 0, 1]])

Post a Comment for "How To Slice A 2d Array Non-consecutively In Python"