8

I have an array of booleans that says which columns of another array I should drop.

For example:

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

I would like to have the following one:

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

All arrays are numpy.array in Python 2.7.

1 Answer 1

9

Once you actually use numpy.arrays, it all 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]])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.