-5

i am currently writing a little ai. This ai needs a lot of data (around 2.7 million). The easy way of giving the libary the input and expected output is by doing the following:

            Double[][] Expected =
        {
            new[] {0.0},
            new[] {0.0},
            new[] {0.0},
            new[] {0.0},
            new[] {1.0},
            new[] {1.0},
            new[] {1.0},
            new[] {1.0}
        };

Because i need 2.7 million arrays in this array, i wrote a little function to do that:

        private static double[][] getIdeal()
    {
        double[][] ideal = new double[2798029][];
        for(int i = 0; i < ideal.Length; i++)
        {
            if (i < 1727310)
            {
                ideal[0][i] = 0.0; <-- Index Out of Range Exception
            }
            else
            {
                ideal[0][i] = 0.0;
            }
        }
        return ideal;
    }

But it throws Out of Range Exception. I think something with the formatting of the initzialization of the variable ideal is wrong, but i don't know what. I want an array with the size of 2798029 with arrays of the size 1 in it. Then i want to set some values of the arrays in the array to 0, the other ones to one. I hope that explains everything.

Thanks you

FritzFurtz
  • 89
  • 1
  • 12
  • if you want array of size 1 why not just put values directly? like `double[]` what is the reason to have array of size 1 in each cell? – M.kazem Akhgary Dec 24 '16 at 22:16
  • It is because as i said i use it for an ai. The libary is called encog. I want to keep everything clean and keep it in the double[][] format. And now i am just curious how to do it. – FritzFurtz Dec 24 '16 at 22:23
  • ok you have to initialize inner arrays too. `ideal[i] = new double[1];` and then `ideal[i][0] = 0.0;` – M.kazem Akhgary Dec 24 '16 at 22:24
  • Now we came to this unclear question from http://stackoverflow.com/questions/41306055/convert-byte-array-to-double-array-in-c-sharp How about explaining your problem clearly instead of what you think is a solution. [What is the XY problem?](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) – L.B Dec 24 '16 at 22:30
  • Tell me what is not clear to you and i will explain it. I think i have explained everything that is needed to answer this question. Of course i can't know that because i do not know the answer. – FritzFurtz Dec 24 '16 at 22:35
  • @FritzFurtz You have a problem and guess the solution is something and ask this. But you are wrong. your questions are non-sense.... Ask your *real , original* problem your professor/boss assigned to you. (including what you have tried so far) – L.B Dec 24 '16 at 22:40
  • @L.B alright got it thank you. Gonna pay more attention to this in future questions. – FritzFurtz Dec 24 '16 at 22:57

1 Answers1

0
        private static double[][] getIdeal()
{
    double[][] ideal = new double[2798029][];
    for(int i = 0; i < ideal.Length; i++)
    {
        ideal[i] = new double[1]; //Note: Initilized ideal[i]
        if (i < 1727310)
        {
            ideal[i][0] = 0.0; <-- No More Index Out of Range Exception 
            //Note: Swapped i and 0.
        }
        else
        {
            ideal[i][0] = 0.0;
        }
    }
    return ideal;
}

ok you have to initialize inner arrays too. ideal[i] = new double[1]; and then ideal[i][0] = 0.0;
– M.kazem Akhgary 12 mins ago

Thank you for the answer.

FritzFurtz
  • 89
  • 1
  • 12
  • congratulations, you completed one more step... But I still think your real problem is still there and not related with this code.... – L.B Dec 24 '16 at 22:58
  • Actually the ai is running now, so i think all my problems (with this code) are fixed. If you mean my real problem is my life, you're right. My real problem is still here. – FritzFurtz Dec 24 '16 at 23:01
  • `If you mean my real problem is my life`. How did you end up with this. I never meant something related with your personality... It is all about how you approach a coding problem... – L.B Dec 24 '16 at 23:03
  • it was a joke... sorry we are not on reddit here. – FritzFurtz Dec 24 '16 at 23:17