gpt4 book ai didi

Java double to INDArray 失去精度

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:48:39 24 4
gpt4 key购买 nike

我无法在不损失精度的情况下将 double 转换为 Nd4j.INDArray。

double[] weight = new double[]{-0.13404223866376802,-0.11294084872465669,0.11232944517596409,-0.01687720880184701,0.13288394029423414,-0.06916641552096867,0.1518882606786481};
INDArray array = Nd4j.create(weight, new int[]{1, 7});
System.out.println(array);

输出是

[-0.13,  -0.11,  0.11,  -0.02,  0.13,  -0.07,  0.15]

期望的输出应该是

[-0.13404223866376802,-0.11294084872465669,0.11232944517596409,-0.01687720880184701,0.13288394029423414,-0.06916641552096867,0.1518882606786481]

如何精确转换?

最佳答案

使用

int precision = 7;
String printed = new NDArrayStrings(precision).format(this);
System.out.println(printed);

以您想要的任何精度。 NDArrayStrings 位于 org.nd4j.linalg.string 包中。

关于Java double to INDArray 失去精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47485402/

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