Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python (numpy): drop columns by index

Tags:

python

numpy

I've got a numpy array and would like to remove some columns based on index. Is there an in-built function for it or some elegant way for such an operation?

Something like:

arr = [234, 235, 23, 6, 3, 6, 23]
elim = [3, 5, 6]

arr = arr.drop[elim]

output: [234, 235, 23, 3]
like image 643
sashkello Avatar asked Mar 01 '13 03:03

sashkello


1 Answers

use numpy.delete, it will return a new array:

import numpy as np
arr = np.array([234, 235, 23, 6, 3, 6, 23])
elim = [3, 5, 6]
np.delete(arr, elim)
like image 174
HYRY Avatar answered Oct 18 '22 17:10

HYRY