I'm trying to find the indices of the minimum values in a Matrix<float>
with MathNet.Numerics
, but only for the values that meet a certain condition (in this case value >= 0
).
I can find one of the minimum actual values like this:
var mat = Matrix<float>.Build.DenseOfArray(new float[,] {
{2, 3, 1},
{3, -1, 5},
{1, 4, 3}
});
var min = mat.Enumerate().Where(x => x >= 0).Min();
But I would like to find the indices of both 1's (and not the -1). So the result should be [0,2] and [2,0].
ANSWER:
I found a possible way to do it, not sure if this is the best/fastest way:
var min = mat.Enumerate().Where(x => x >= 0).Min();
var allMin = mat.EnumerateIndexed().Where(x => x.Item3 == min).ToList();