7

I have a numpy array that looks like this

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

I want it like this after deleting first column

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

so currently the dimension is 3*3*3, after removing the first column it should be 3*3*2

0

2 Answers 2

11

You can slice it as so, where 1: signifies that you only want the second and all remaining columns from the inner most array (i.e. you 'delete' its first column).

>>> a[:, :, 1:]
array([[[2, 3],
        [5, 6]],

       [[8, 9],
        [9, 4]],

       [[1, 3],
        [3, 6]]])
Sign up to request clarification or add additional context in comments.

Comments

8

Since you are using numpy I'll mention numpy way of doing this. First of all, the dimension you have specified for the question seems wrong. See below

x = np.array([
[[1,2,3], [4,5,6]],
[[3,8,9], [2,9,4]],
[[7,1,3], [1,3,6]]
])

The shape of x is

x.shape
(3, 2, 3)

You can use numpy.delete to remove a column as shown 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 of a

a.shape
(3, 2, 2)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.