How to filter columns in numpy ndarray

I have an array booleansthat says which columns of another array I should delete.

For instance:

selections = [True, False, True]
data = [[ 1, 2, 3 ],
        [ 4, 5, 6 ]]

I would like to have the following:

new_data = [[ 1, 3 ],
            [ 4, 6 ]

All arrays numpy.arrayin Python 2.7.

+4
source share
1 answer

Once you use numpy.arrays, everything works:

import numpy as np

selections = np.array([True, False, True])
data = np.array([[ 1, 2, 3 ],
        [ 4, 5, 6 ]])

>>> data[:, selections]
array([[1, 3],
       [4, 6]])
+4
source

All Articles