java - 使用 UJMP 库时如何从文件导入/导出矩阵?

标签 java matrix import export ujmp

我正在尝试开发 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 矩阵?

提前感谢您的回复,并对我的英语表示抱歉。

最佳答案

我不确定,但我认为您在文件中使用 null 作为分隔符:

m.exportToFile(FileFormat.TXT,"test.txt",null);

也许你应该使用:

m.exportToFile(FileFormat.TXT,"test.txt",";");

关于java - 使用 UJMP 库时如何从文件导入/导出矩阵?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23996859/

相关文章:

python - 如何在Python中导入S3cmd

java - 如何通过excel导入实体及其依赖对象

java - 如何在远程 jmx URL 的 java 中获取所有垃圾收集器 MX bean?

java - Websphere MQ 消息被清除(破坏性读取)而不是被浏览

java - 如何在 Android 中调整 LayerDrawable 中的 Drawable 大小和位置

c++ - 寻找一个C++开源的矩阵存储库

Java导入类System

java - Float 和 Double NaN(非数字)值

css - react native 矩阵 2d 的正确方法?

android - 拉伸(stretch)/缩放 View /位图的特定区域