How to remove a column in a 3d numpy array
I have a numpy array that looks like
[
[[1,2,3], [4,5,6]],
[[3,8,9], [2,9,4]],
[[7,1,3], [1,3,6]]
]
I want this to happen after removing the first column
[
[[2,3], [5,6]],
[[8,9], [9,4]],
[[1,3], [3,6]]
]
so currently the size is 3 * 3 * 3, after removing the first column it should be 3 * 3 * 2
+3
source to share
2 answers
Since you are using numpy, I mentioned how to do this. First of all, the measurement you provided for the question seems to be wrong. See below
x = np.array([
[[1,2,3], [4,5,6]],
[[3,8,9], [2,9,4]],
[[7,1,3], [1,3,6]]
])
Form x is
x.shape
(3, 2, 3)
You can use numpy.delete to delete a column like below
a = np.delete(x, 0, 2)
a
array([[[2, 3],
[5, 6]],
[[8, 9],
[9, 4]],
[[1, 3],
[3, 6]]])
To find the shape
a.shape
(3, 2, 2)
+5
source to share