我正在尝试使用多维数组([verybigrow][2])创建矩阵算术运算方法。我是新手,我只是找不到我做错了什么。如果有人帮助我告诉我它是什么,我真的很感激。
try {
Stream<String> Matrix = Files.lines(Paths.get(file)).parallel();
String[][] DataSet = Matrix.map(mapping -> mapping.split(",")).toArray(String[][]::new);
Double[][] distanceTable = new Double[DataSet.length - 1][];
/* START WANT TO REPLACE THIS MATRIX CALCULATION WITH PARALLEL STREAM RATHER THAN USE TRADITIONAL ARRAY ARITHMETICS START */
for (int i = 0; i < distanceTable.length - 1; ++i) {
distanceTable[i] = new Double[i + 1];
for (int j = 0; j <= i; ++j) {
double distance = 0.0;
for (int k = 0; k < DataSet[i + 1].length; ++k) {
double difference = Double.parseDouble(DataSet[j][k]) - Double.parseDouble(DataSet[i + 1][k]);
distance += difference * difference;
}
distanceTable[i][j] = distance;
}
}
/* END WANT TO REPLACE THIS MATRIX CALCULATION WITH PARALLEL STREAM RATHER THAN USE TRADITIONAL ARRAY ARITHMETICS START */
} catch ( Exception except ){
System.out.println ( except );
}
我宁愿不使用库或类似的东西,我这样做主要是为了了解它是如何工作的。预先非常感谢您。如果你询问数据看起来像:
4,53
5,63
10,59
9,77
13,49
数据处理的输出应如下所示:
[101] <- ((4-5)^2) + ((53-63)^2)
[72, 41] <- ( ((4-10)^2) + ((53-59)^2) ), ( ((5,10)^2) + ((63-59)^2))
[601.0, 212.0, 325.0]
[97.0, 260.0, 109.0, 800.0]
[337.0, 100.0, 109.0, 80.0, 400.0]
慕标5832272
RISEBY
相关分类