C # Filling in double [] [] manually

I am just trying to use the source code. This source code has the following line:

double[][] inputs = sourceMatrix.Submatrix(null, 0, 1).ToArray(); 

Initially, these β€œinputs” are filled using a matrix, but I'm still too inexperienced to use this matrix. First, I would like to test it with some manually encoded values.

Can someone please tell me how to populate double [] [] with some values?

Actually I am not familiar with C # yet. I assume that [] [] means a three-dimensional array.

In VB6, I just say

 Redim inputs(2,2) 

and then:

 inputs(0,0) = 64 inputs(0,1) = 92 inputs(0,2) = 33 inputs(1,0) = 4 inputs(1,1) = 84 inputs(1,2) = 449 

etc...

But I think this is not so easy in C #. If anyone could help, I would be very happy.

Thanks.

+4
source share
5 answers

a double[][] is a gear array - an array of arrays. To fill this, you must fill the external array with a set of double[] arrays. However, I expect that you need a rectangular array: double[,] , for example new double[3,2] . There is a short command to initialize such arrays:

 double[,] data = new double[2, 3] { { 64, 92, 33 }, { 4, 84, 449 } }; double val = data[1, 2]; // 449.0 
+9
source

You have an array of arrays. Therefore, you should initialize them as follows:

 double[][] inputs = new double[][] { new double[] { 1, 2, 3 }, new double[] { 4, 5, 6 }, new double[] { 7, 8, 9 } }; 

If you have two sizes of the array ( inputs[,] ), then this will be:

 double[,] inputs = new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; 

But, as John Skeet said, reading about arrays is the first thing you should do.

+1
source

To make it very simple:

 double[][] inputs = new double[3][]; inputs[0] = new double[3]; inputs[1] = new double[3]; inputs[2] = new double[3]; inputs[0][0] = 1; inputs[0][1] = 2; inputs[0][2] = 3; inputs[1][0] = 4; inputs[1][1] = 5; inputs[1][2] = 6; inputs[2][0] = 7; inputs[2][1] = 8; inputs[2][2] = 9; 
+1
source

Take a look at using double[,] , this is what you need Arrays

0
source

double [] [] is a gear array. You probably mean double [,], which is a two-dimensional array.

Initializing a two-dimensional array:

 double[,] matrix = new double[3,2] = {{1,2} {3,4}, {4,5}} 

You already have examples for initializing gear arrays, from other answers.

The difference between jagged and true multidimensional arrays in practice is that jagged arrays are arrays of arrays, so they may not be rectangular, that is, a matrix, therefore, jagged:

 double[][] jagged = new double[2] { new double[4], new double[2] }; 

The way they are laid out in memory is also different. A multidimensional array is the only reference to contiguous memory space. Hard arrays are a true array of arrays.

Read more about it here.

0
source

All Articles