I need to remove some rows from a 3D numpy array. For exampe:
JavaScript
x
8
1
a = [[1,2,3]
2
[4,5,6]
3
[7,8,9]
4
5
[9,8,7]
6
[6,5,4]
7
[3,2,1]]
8
and I want to remove the third row of both pages of the matrix in order to obtain something like:
JavaScript
1
6
1
a = [[1,2,3]
2
[4,5,6]
3
4
[9,8,7]
5
[6,5,4]]
6
I have tried with
JavaScript
1
2
1
a = numpy.delete(a, 2, axis=0)
2
but I can’t obtain what I need.
Advertisement
Answer
axis
should 1
.
JavaScript
1
14
14
1
>>> import numpy
2
>>> a = [[[1,2,3],
3
4,5,6], [
4
7,8,9]], [
5
9,8,7], [[
6
6,5,4], [
7
3,2,1]]] [
8
>>> numpy.delete(a, 2, axis=1)
9
array([[[1, 2, 3],
10
[4, 5, 6]],
11
12
[[9, 8, 7],
13
[6, 5, 4]]])
14