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?

7
  • 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. Commented May 12, 2015 at 4:55
  • That already looks like a row matrix (row vector?) of [1, 0, 1, 0]. What is your intended output? Commented May 12, 2015 at 5:07
  • output will be same as [1, 0, 1, 0]; only the object type should change. Commented May 12, 2015 at 5: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? Commented May 12, 2015 at 5:12
  • 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! Commented May 12, 2015 at 5:19

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.