Reputation: 77
I've got problem with types while working with vectors in MathNet.
I'm using
using MathNet.Numerics.LinearAlgebra.Double;
so all Vectors and Matrices are type Double.Vector
etc.
But for example if I want to get particular row from matrix ->
V.Row(V.RowCount-1);
it returns type Vector<double>
, so this throws "cant convert" error:
Vector v = myMatrix.Row(0);
Is there some Vector<double>
to Double.Vector
convertor or trick how its done?
Upvotes: 2
Views: 2561
Reputation: 4736
Double.Vector
inherits Vector<double>
, so normal type casting should work, e.g. Vector v = (Vector)myMatrix.Row(0);
.
However, since Math.NET Numerics v3 it is recommended to use the generic types only (Vector<double>
). The API is designed such that with the generic types you never have to do any such conversions or casts. There's even no need to open the MathNet.Numerics.LinearAlgebra.Double
namespace, MathNet.Numerics.LinearAlgebra
is enough when using the CreateVector
static class to create new vectors, and AsArray
to get back to the raw array if needed.
Upvotes: 2