Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove range of columns in numpy array

I have an array :

e = np.array([[ 0,  1,  2,  3, 4, 7, 4],
              [ 4,  5,  6,  7, 2, 3, 1],
              [ 8,  9, 10, 11, 3, 5, 7]])

I want to remove the range of columns from column 1 to column 3, so it should return:

e = np.array([[ 0,  4, 7, 4],
              [ 4,  2, 3, 1],
              [ 8,  3, 5, 7]])

I've seen some solution , but they remove specific column by its index, not in range, how to solve it? Thanks

like image 432
mfathirirhas Avatar asked Feb 24 '16 04:02

mfathirirhas


2 Answers

Solved it using :

np.delete(e,np.s_[1:3],axis=1)

It will delete column in range 1 until 3.

like image 126
mfathirirhas Avatar answered Sep 28 '22 05:09

mfathirirhas


e = np.array([[ 0,  1,  2,  3, 4, 7, 4],

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

              [ 8,  9, 10, 11, 3, 5, 7]])

np.delete(e, [1,3], axis=1)

>>>array([[ 0,  2,  4,  7,  4],
       [ 4,  6,  2,  3,  1],
       [ 8, 10,  3,  5,  7]])
like image 22
seanmus Avatar answered Sep 28 '22 06:09

seanmus