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.
Advertisement
Answer
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]]])