Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to remove some rows from a 3D numpy array. For exampe:

a = [[1,2,3]
     [4,5,6]
     [7,8,9]

     [9,8,7]
     [6,5,4]
     [3,2,1]]

and I want to remove the third row of both pages of the matrix in order to obtain something like:

 a = [[1,2,3]
     [4,5,6]

     [9,8,7]
     [6,5,4]]

I have tried with

   a = numpy.delete(a, 2, axis=0)

but I can't obtain what I need.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

axis should 1.

>>> import numpy
>>> a = [[[1,2,3],
...       [4,5,6],
...       [7,8,9]],
...      [[9,8,7],
...       [6,5,4],
...       [3,2,1]]]
>>> numpy.delete(a, 2, axis=1)
array([[[1, 2, 3],
        [4, 5, 6]],

       [[9, 8, 7],
        [6, 5, 4]]])
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.