Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I am getting an IndexOutOfRange exception when filling the values of the arrays below from a stored. In total the list contains 36720 items which I have output to .csv to confirm. Any help please as I cannot tell where I am having an out of bounds error

C#
int inputToMain = 300;             
static int inputToHidden = 120;    
static int hiddenToOutput = 6; 
double[][] arrayWeightToHidden = new double[inputToHidden][];       
double[][] arrayWeightToOutput = new double[hiddenToOutput][];

C#
public void TestSample(List<Double> storedWeights)
        {

            for (int i = 0; i < arrayWeightToHidden.Length; i++)
            {
                arrayWeightToHidden[i] = new double[inputToMain];
            }


            //fill
            int h = 0;
            for (int i = 0; i < inputToHidden; i++)
            {
                for (int j = 0; j < inputToMain; j++)
                {
                      arrayWeightToHidden[i][j] = storedWeights.ElementAt(h);
                      h++;
                }
            }
 


            for (int i = 0; i < arrayWeightToOutput.Length; i++)
            {
                arrayWeightToOutput[i] = new double[hiddenToOutput];

            }

            //fill
            for (int i = 0; i < hiddenToOutput; i++)
            {
                for (int j = 0; j < inputToHidden; j++)
                {
                    arrayWeightToOutput[i][j] = storedWeights.ElementAt(h);
                    h++;
                }
            }
}


part of the storing method
C#
for (int i = 0; i < inputToHidden; i++)
          {
              for (int j = 0; j < inputToMain; j++)
              {
                  returnOutput.Add(arrayWeightToHidden[i][j]);                  
              }
          }
          for (int i = 0; i < hiddenToOutput; i++)
          {
              for (int j = 0; j < inputToHidden; j++)
              {
                  returnOutput.Add(arrayWeightToOutput[i][j]);                  
              }
          }
Posted
Comments
Mohd. Mukhtar 23-Nov-12 23:51pm    
On which line you are getting error.
datt265 24-Nov-12 1:53am    
ok solved

1 solution

Looks like you are using the wrong size here:
C#
for (int i = 0; i < arrayWeightToOutput.Length; i++)
{
    arrayWeightToOutput[i] = new double[hiddenToOutput]; 
}

You should be using inputToHidden instead:
C#
for (int i = 0; i < arrayWeightToOutput.Length; i++)
{
    arrayWeightToOutput[i] = new double[inputToHidden]; 
}
 
Share this answer
 
Comments
datt265 23-Nov-12 18:04pm    
ok yes i realized later

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900