Reputation: 796
I have an integer array named resp
I want to rewrite/convert it as/to a row matrix
with name resp
.
int[] resp= {1, 0, 1, 0};
I am using the Mathnet.Numerics library.
How can I do that?
Upvotes: 2
Views: 2973
Reputation: 15425
In Mathnet, you are not able to initialize an array of integers. As it is, there's in limited support available for this. If you tried, you would get this:
Unhandled Exception: System.TypeInitializationException: The type initializer
for 'MathNet.Numerics.LinearAlgebra.Vector`1' threw an exception. --->
System.NotSupportedException: Matrices and vectors of type 'Int32'
are not supported. Only Double, Single, Complex or Complex32 are supported at this point.
You can initialize a vector with similar values (with doubles) like this:
var resp = new [] {1.0, 0.0, 1.0, 0.0};
var V = Vector<double>.Build;
var rowVector = V.DenseOfArray(resp);
In order to build a matrix, you would need a multi-dimensional array.
Upvotes: 2