# Remove columns basing on binary sequence

Possibly it is duplicate, still I could not find here elegant way to remove matrix columns basing on binary sequence. i.e. if I apply {1,1,0,0,1,0,1} to matrix it should delete columns 3,4 and 6.

• You can simply use matrix[[All, Pick[Range@Last@Dimensions@matrix, mask, 1]]], where matrix is your matrix, and mask is in your case {1,1,0,0,1,0,1}. – Leonid Shifrin Jun 27 '16 at 18:38
• Another option: matrix[[All, Flatten[Position[{1, 1, 0, 0, 1, 0, 1}, 1]]]] – Coolwater Jun 27 '16 at 18:52
• Also, Pick[Transpose[matrix], {1, 1, 0, 0, 1, 0, 1}, 1] // Transpose – Bob Hanlon Jun 27 '16 at 19:20
• Similar to @BobHanlon's: Pick[matrix, Table[{1, 1, 0, 0, 1, 0, 1}, {Length@matrix}], 1]. Or, just to be safe: Pick[matrix, Table[PadRight[{1, 1, 0, 0, 1, 0, 1}, Last@Dimensions@matrix], {Length@matrix}], 1]. – march Jun 27 '16 at 20:37
• Also for Mathematica 10 or higher: matrix[[;; , PositionIndex[{1, 1, 0, 0, 1, 0, 1}]]] – user1066 Jun 16 '17 at 12:32

Various solutions were posted in comments:

matrix = RandomInteger[10, {3, 7}];
mask = {1, 1, 0, 0, 1, 0, 1};

(* Leonid Shifrin *)