Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
 
int inputToMain = 300;             
static int inputToHidden = 120;    
static int hiddenToOutput = 6; 
double[][] arrayWeightToHidden = new double[inputToHidden][];       
double[][] arrayWeightToOutput = new double[hiddenToOutput][];
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
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 23-Nov-12 11:34am
bmw318mt1.2K
Comments
Mohd. Mukhtar at 23-Nov-12 23:51pm
   
On which line you are getting error.
bmw318mt at 24-Nov-12 1:53am
   
ok solved

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Looks like you are using the wrong size here:
for (int i = 0; i < arrayWeightToOutput.Length; i++)
{
    arrayWeightToOutput[i] = new double[hiddenToOutput]; 
}
You should be using inputToHidden instead:
for (int i = 0; i < arrayWeightToOutput.Length; i++)
{
    arrayWeightToOutput[i] = new double[inputToHidden]; 
}
  Permalink  
Comments
bmw318mt at 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)

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100