2

Libraries like numpy for python make it really simple to check whether two matrices are almost equal (numpy.allclose/numpy.isclose). I couldn't find anything similar for math.net. How would I check that two matrices are equal up to a tolerance in math.net?

emilaz
  • 1,722
  • 1
  • 15
  • 31

1 Answers1

2

Ok I found it, MathNet.Numerics.Precision includes what I was looking for. Works for vectors, matrices, and a whole lot of other data types. Can be used as follows

using MathNet.Numerics

var foo =  CreateMatrix.DenseIdentity<double>(3);
var bar =  CreateMatrix.DenseIdentity<double>(3);
var tolerance = 1e-5;
Precision.AlmostEqual(foo, bar, tolerance);
// or even simpler...
foo.AlmostEqual(bar, tolerance);

Not sure why I missed it at my first google attempts, but in case anyone else is struggling with this I'm keeping this up.

emilaz
  • 1,722
  • 1
  • 15
  • 31