2

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?

jdphenix
  • 15,022
  • 3
  • 41
  • 74
Artiga
  • 776
  • 2
  • 16
  • 37
  • 2
    What is the definition of the array `resp`? You've provided literally none of the information anyone would need to give you an applicable answer. – jdphenix May 12 '15 at 04:55
  • That already looks like a row matrix (row vector?) of `[1, 0, 1, 0]`. What is your intended output? – jdphenix May 12 '15 at 05:07
  • output will be same as [1, 0, 1, 0]; only the object type should change. – Artiga May 12 '15 at 05:09
  • Okay, so what type are what wanting to convert it to? As far as I know, .NET doesn't have a specific type to represent a row vector, but an array as you have now is a reasonable approximation. Are you using a library that you've not included information about in your question? – jdphenix May 12 '15 at 05:12
  • I want to convert it to a matrix. Libraries which I am using using System; using System.Collections.Generic; using System.Linq; using System.Text; using MathNet.Numerics.Distributions; using MathNet.Numerics.LinearAlgebra.Factorization; using MathNet.Numerics.Optimization; – Artiga May 12 '15 at 05:15
  • .NET does not have a built-in representation of a general purpose matrix. – jdphenix May 12 '15 at 05:17
  • 2
    I've edited in the critical minimum information necessary for anyone to give you a reasonable answer for your question. In the future, please do your best to include this information in your question's first iteration. Thank you! – jdphenix May 12 '15 at 05:19

1 Answers1

2

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.

jdphenix
  • 15,022
  • 3
  • 41
  • 74