列表与LT;列表与LT;双>>为JAMA或其他库双重[] [] [英] List<List<Double>> to double[][] for JAMA or other libs
问题描述
我无法让我的列表>双重[] []工作在线性代数包,如 JAMA 的。
基本上我有一些类似这样的坐标列表:
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]]
我正在尝试将这些坐标放在 JAMA 类是double [] []。
我试图使用方法toArray,但是我失败了。
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()][]);
如何做?或者还有其他套餐可以应付SVD,这里需要使用列表吗?
How to do that? Or is there other packages to cope with SVD, which i need here, using List of Lists?
推荐答案
番石榴有一个双重类,其中有一个 toArray
需要一个 Collection<?扩展Number>
,从而获取列表< Double>
并转换为数组。所以...
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));
}
这篇关于列表与LT;列表与LT;双>>为JAMA或其他库双重[] []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!