Вопрос

i cannot get my List> to double[][] to work on linear algebra package like JAMA. Basically i have some sort of List with coordinates like this :

[[2.63, 11.087, -12.054], 
[2.357, 13.026, -15.29], 
[1.365, 16.691, -15.389], 
[0.262, 18.241, -18.694]]

And i am trying to put these coordinates to JAMA class which is double[][]. I tried to use method toArray, but i failed.

double[][] array = list.toArray(new double[list.size()][]);

How to do that? Or is there other packages to cope with SVD, which i need here, using List of Lists?

Это было полезно?

Решение

Guava has a Doubles class which has a toArray that takes a Collection<? extends Number> and will thereby take a List<Double> and convert to an array. So...

List<List<Double>> myList;
double[][] myArray = new double[myList.size()][];
for (int i=0, n<myList.size(); i<n; i++){
     myArray[i] = Doubles.toArray(myList.get(i));
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top