问题
First of all, ec here is of type ArrayList, which means ec.get(i) should return Double[] and not ArrayList.
Second, double and Double are completely different types. You can’t simply use row.toArray(new double[row.size()]) on your code.
解决方案
1.
如果您想要真正的Double的2D ArrayList,则ec的类型应为ArrayList< ArrayList< Double>>.但是因为不能使用toArray(),所以我们改为手动循环.
public ArrayList> ec; // line changed here
public double[][] ei;
...
encogCorpus = new ArrayList>(); // and here also
...
ec.add(inputs); // `inputs` here should be of type `ArrayList`
...
ei = new double[ec.size()][];
for (int i = 0; i < ec.size(); i++) {
ArrayList row = ec.get(i);
// Perform equivalent `toArray` operation
double[] copy = new double[row.size()];
for (int j = 0; j < row.size(); j++) {
// Manually loop and set individually
copy[j] = row.get(j);
}
ei[i] = copy;
}
2.
但是,如果您坚持使用ArrayList< Double []> ;,则只需更改主要部分:
public ArrayList ec;
public double[][] ei;
...
encogCorpus = new ArrayList();
...
ec.add(inputs);
...
ei = new double[ec.size()][];
for (int i = 0; i < ec.size(); i++) {
// Changes are only below here
Double[] row = ec.get(i);
double[] copy = new double[row.length];
// Still, manually loop...
for (int j = 0; j < row.length; j++) {
copy[j] = row[j];
}
ei[i] = copy;
}
3.
最后,如果您可以将Double []更改为double [],则解决方案2将变为:
public ArrayList ec; // Changed type
public double[][] ei;
...
...
for (int i = 0; i < ec.size(); i++) {
// Simpler changes here
ei[i] = ec.get(i).clone();
}
...