gpt4 book ai didi

java - RCaller 获取未知大小的矩阵

转载 作者:太空宇宙 更新时间:2023-11-04 15:00:41 25 4
gpt4 key购买 nike

我在 Java 中使用 RCaller 来执行外部 R 程序。

问题是,我不知道矩阵的确切大小,但 .getAsDoubleMatrix() 方法想要知道该大小。

double[][] matrix = caller.getParser().getAsDoubleMatrix("result", DONT_KNOW, DONT_KNOW);

有没有办法保持尺寸动态?

最佳答案

revision e263b5393d43 ,RoutputParser 类现在具有 getDimensions() 方法,用于获取矩阵的未知维度。这是通过的测试文件:

int n = 21;
int m = 23;
double[][] data = new double[n][m];
for (int i=0;i<data.lengthi++){
for (int j=0;j<data[0].length;j++){
data[i][j] = Math.random();
}
}
RCaller caller = new RCaller();
Globals.detect_current_rscript();
caller.setRscriptExecutable(Globals.Rscript_current);

RCode code = new RCode();
code.addDoubleMatrix("x", data);
caller.setRCode(code);

caller.runAndReturnResult("x");

int[] mydim = caller.getParser().getDimensions("x");

Assert.assertEquals(n, mydim[0]);
Assert.assertEquals(m, mydim[1]);

最新编译的jar不包含此更新,但是,我计划下周准备2.3版本,或者您可以立即下载源代码并自行编译。

访问 RCaller 官方博客页面了解最新版本 here

关于java - RCaller 获取未知大小的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22609160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com