slicing array based on selection masks
.net, arrays, c#, linq
Solution
You can achieve this using LINQ:
double[] a = new double[]{1.0, 2.0, 3.0};
bool[] b = new bool[]{true, false, true};
var result = a.Where((item, index)=>b[index]);
Problem
Given two arrays: ``` double[] a = new double[]{1.0, 2.0, 3.0}; bool[] b = new bool[]{true, false, true}; ``` Is there an easy way to select in `a` based on `b`? In R and other scripting languages you would say: ``` a[b] ``` to get `{1.0, 3.0}`. I can not figure out if there is a clean (no explicit loops involved) way to do this in C#. Maybe I should organise my data differently?