Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to slice all the columns except first column in numpy array?

Tags:

python-3.x

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.

like image 999
Govinda Kc Avatar asked Oct 31 '25 04:10

Govinda Kc


1 Answers

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]])
like image 122
Riley Avatar answered Nov 02 '25 22:11

Riley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!