Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get multiple column from python numpy array

I have a numpy array as "data". I want to retrieve all its field except the 6th field. Currently I am using following code:

x = data[:,[0,1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17]]  

which is solving the purpose, but I feel it is not the correct way.

I tried many other ways to do it, like:

   x = data[:, [:,6 and 7,:]],  
   x = data[:, [:,6 or 7,:]], etc  

but nothing seems to be working.

I also checked at several other places, but could not find any solution. Please suggest some easy way to do it.

like image 534
Shweta Avatar asked May 20 '26 20:05

Shweta


1 Answers

For a more general answer (if you need to discard several columns):

import numpy
x =  numpy.array(data)[:,range(0,6)+range(7,18)]
like image 119
nicolas Avatar answered May 22 '26 14:05

nicolas