关于数组和列表的问题 [英] Question about arrays and list

查看:98
本文介绍了关于数组和列表的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,当我从存储中填充下面的数组的值时,我得到一个IndexOutOfRange异常.该列表总共包含36720个项目,我已将它们输出到.csv进行确认.请提供任何帮助,因为我无法确定我在哪里出现错误

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]);                  
              }
          }

推荐答案

好像在这里使用了错误的大小:
Looks like you are using the wrong size here:
for (int i = 0; i < arrayWeightToOutput.Length; i++)
{
    arrayWeightToOutput[i] = new double[hiddenToOutput]; 
}


您应该使用inputToHidden代替:


You should be using inputToHidden instead:

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


这篇关于关于数组和列表的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆