Skip to content Skip to sidebar Skip to footer

Delete A Column In A Multi-dimensional Array If All Elements In That Column Satisfy A Condition

I have a multi-dimensional array such as; a = [[1,1,5,12,0,4,0], [0,1,2,11,0,4,2], [0,4,3,17,0,4,9], [1,3,5,74,0,8,16]] How can I delete the column if all entries w

Solution 1:

With the code you already have, you can just do:

forplaceinind:
    forsublistina:
        delsublist[place]

Which gets the job done but is not very satisfactory...


Edit: numpy is strong

import numpy as np
a = np.array(a)
a = a[:, np.sum(a, axis=0)!=0]

Post a Comment for "Delete A Column In A Multi-dimensional Array If All Elements In That Column Satisfy A Condition"