Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array indexing in numpy

Tags:

python

numpy

Is there a way in numpy to retrieve all items in an array except the item of the index provided.

 x = 
 array([[[4, 2, 3],
    [2, 0, 1],
    [1, 3, 4]],

   [[2, 1, 2],
    [3, 2, 3],
    [3, 4, 2]],

   [[2, 4, 1],
    [0, 2, 2],
    [4, 0, 0]]])

and by asking for

x[not 1,:,:] 

you will get

array([[[4, 2, 3],
    [2, 0, 1],
    [1, 3, 4]],

   [[2, 4, 1],
    [0, 2, 2],
    [4, 0, 0]]])

Thanks

like image 229
JustInTime Avatar asked Dec 28 '22 08:12

JustInTime


1 Answers

In [42]: x[np.arange(x.shape[0])!=1,:,:]
Out[42]: 
array([[[4, 2, 3],
        [2, 0, 1],
        [1, 3, 4]],

       [[2, 4, 1],
        [0, 2, 2],
        [4, 0, 0]]])
like image 199
unutbu Avatar answered Dec 31 '22 12:12

unutbu