python - remove a specific column in numpy -


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

i deleting 3rd column

>>> np.hstack(((np.delete(arr, np.s_[2:], 1)),(np.delete(arr, np.s_[:3],1)))) array([[ 1,  2,  4],        [ 5,  6,  8],        [ 9, 10, 12]]) 

are there better way ? please consider novice question.

if ever want delete more 1 columns, pass indices of columns want deleted list, this:

>>> = np.arange(12).reshape(3,4) >>> array([[ 0,  1,  2,  3],        [ 4,  5,  6,  7],        [ 8,  9, 10, 11]]) >>> np.delete(a, [1,3], axis=1) array([[ 0,  2],        [ 4,  6],        [ 8, 10]]) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -