Search code examples
arraysilnumerics

How can I filter rows based on multiple criteria from an array in IlNumerics


I would like get rows based on multiple constraints. One criteria works perfect like

A[A[full, 0] % 3 == 0, full];

But when I add a second criteria I get a compiler error. What is the correct way of doing this?

Array<double> A = new double[,] {
              { 1, 9, 20 },
              { 2, 11, 21 },
              { 9, 12, 21 },
              { 9, 13, 23 },
              { 9, 14, 24 },
              { 10, 12, 21 },
              { 14, 13, 23 },
              { 16, 14, 24 },
              { 19, 12, 21 },
              { 27, 13, 23 },
              { 23, 14, 24 },
              { 6, 15, 25 }
            };

            Array<double> matching = 
                A[A[full, 0] % 3 == 0 && A[full, 1] > 10, full];

Solution

  • The && operator is not overloaded for Array<T>. It returns a bool in C# - not an array as you might expect. Use the corresponding function ILMath.and(A, B) instead and it will work.