我正在尝试使用 UJMP 库。我创建了一个矩阵,我想将其导出为 txt 文件,然后将其作为基本矩阵再次导入。我尝试了以下代码,但它不起作用:
Matrix m = MatrixFactory.dense(ValueType.INT, new long[]{(long)100,(long)100});
for(int i = 0; i< 100; i++){
for(int j = 0; j< 100;j++){
m.setAsInt((int) (Math.random() *3),new long[]{i,j});
}
}
try {
m.exportToFile(FileFormat.TXT,"test.txt",null); //this works. My file contains the matrix
} catch (MatrixException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Matrix n = null;
try {
n =ImportMatrix.fromFile(FileFormat.TXT,new File("test.txt"),null); //this doesn't work. The matrix has a size of 1*1 and contains the content of the previous matrix as a single string.
} catch (MatrixException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(n.getSize()[0]+" "+n.getSize()[1]); // I get 1 1;
那么我应该怎么做才能让我的原始矩阵成为 100*100 矩阵?
提前感谢您的回复,对不起我的英语。