Java Ojalgo-从CSV加载矩阵
我有一些大的头CSV文件,其中包含我想加载到矩阵中的值 我遇到过LineSplittingParser类,但找不到关于如何使用它从文件中实际获取矩阵对象的好例子Java Ojalgo-从CSV加载矩阵,java,csv,ojalgo,Java,Csv,Ojalgo,我有一些大的头CSV文件,其中包含我想加载到矩阵中的值 我遇到过LineSplittingParser类,但找不到关于如何使用它从文件中实际获取矩阵对象的好例子 有人能举一个小例子来说明如何实现这一点吗?不确定LineSplittingParser是读取矩阵的一个很好的替代方法,但类似的方法可能会奏效: File fileToParse = null; // You have to know the number of rows and columns int numRows = 9, numC
有人能举一个小例子来说明如何实现这一点吗?不确定LineSplittingParser是读取矩阵的一个很好的替代方法,但类似的方法可能会奏效:
File fileToParse = null;
// You have to know the number of rows and columns
int numRows = 9, numCols = 9;
Primitive64Store matrix = Primitive64Store.FACTORY.make(numRows, numCols);
LineSplittingParser parser = new LineSplittingParser("\\s+", true);
AtomicInteger row = new AtomicInteger();
boolean skipHeader = true;
parser.parse(fileToParse, skipHeader, line -> {
int i = row.intValue();
for (int j = 0; j < line.length; j++) {
matrix.set(i, j, Double.parseDouble(line[j]));
}
row.incrementAndGet();
});
文件fileToParse=null;
//您必须知道行和列的数量
int numRows=9,numCols=9;
Primitive64Store矩阵=Primitive64Store.FACTORY.make(numRows,numCols);
LineSplittingParser=newlinesplittingparser(“\\s+”,true);
AtomicInteger行=新的AtomicInteger();
布尔skipHeader=true;
parser.parse(fileToParse,skipHeader,line->{
int i=行。intValue();
对于(int j=0;j
这段代码没有经过测试-它只是一个大纲-您必须用文件中使用的任何分隔符替换
“\\s+”
。如果有比LineSplittingParser更好的方法,我很乐意听到。特别是考虑到我不会提前知道共谋和争吵的数量。