1
什麼是快速讀取所有雙精度矩陣的快速方法(在這個矩陣中沒有NAs缺失的元素)。大多數參賽作品是非零雙打,也許有30%是零。尺寸大約100萬行100列。高效讀取雙精度矩陣的方法
我正在使用的功能如下。但是,對於1千兆字節以上的矩陣來說,它非常慢。
我該如何更快地做到這一點?以下任何幫助: - 不要保存爲csv並閱讀它,請嘗試保存爲二進制格式或其他格式。 - 將矩陣轉置到數據文件中,然後逐列讀取,而不是逐行讀取,如下面的函數所做的那樣。 - 以某種方式將矩陣序列化爲Java對象以便重新讀取。
private static Vector<Vector<Double>> readTXTFile(String csvFileName, int skipRows) throws IOException {
String line = null;
BufferedReader stream = null;
Vector<Vector<Double>> csvData = new Vector<Vector<Double>>();
try {
stream = new BufferedReader(new FileReader(csvFileName));
int count = 0;
while ((line = stream.readLine()) != null) {
count += 1;
if(count <= skipRows) {
continue;
}
String[] splitted = line.split(",");
Vector<Double> dataLine = new Vector<Double>(splitted.length);
for (String data : splitted) {
dataLine.add(Double.valueOf(data));
}
csvData.add(dataLine);
}
} finally {
if (stream != null)
stream.close();
}
return csvData;
}