I have a 2D numpy array (i.e. matrix) A , which contains useful data intersecting with garbage in the form of column vectors, and also a selection array B , which contains "1" for these columns which are important, and 0 for those who does not do this. Is there a way to select only those columns from A that correspond to units in B ? i.e. matrix
A = array([[ 0, 1, 2, 3, 4], and a vector B = array([ 0, 1, 0, 1, 0]) [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]])
I want too
array([[1, 3], [6, 8], [11, 13], [16, 18], [21, 23]])
Is there an elegant way to do this? Right now, I have a for loop that iterates through B
NOTE. The matrices I'm dealing with are large, so I don't want to use numpy masked arrays, since I just don't want masked data