4

I am trying to slice the columns of numpy array in python.

How to print all the columns except first one? Imagine I have large dimensions of numpy array not the simple one.

1 Answer 1

6

First, create an array in Python, then, use slicing to extract everything but the first column:

import numpy as np
a = np.array([[1,2,3], [4,5,6], [7,8,9]])
sliced = a[:,1:]
print(sliced)

output:

array([[2, 3],
       [5, 6],
       [8, 9]])
Sign up to request clarification or add additional context in comments.

2 Comments

@GovindaKc, no problem. If my response answered your question, please accept it :-)
I accepted the solution but is not displayed @Riley. It says: because of less than 125 reputations, scores are not displayed :(

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.