英文:
Reduction of numbers accuracy in ND4J
问题
我有一个名为“real”的数组,它包含一组双精度数。我试图基于我的向量创建一个INDArray。
我的代码如下:
double real_d = (double) ArrBD.get(0);
INDArray real = Nd4j.create(real_d);
它可以工作,但不幸的是,它会将大的数字转换为无穷大,将小的数字转换为零。
在这里,您可以看到双精度数组:
[0.0, 5.911259568298103E-306, -1.8401529637727614E-221, 1.7562463582928743E-268, 2.7206514809021945E-133, 4.583815262762733E90, 2.5637698710586 ....
以及这里是INDArray的数据:
[0.0,0.0,-0.0,0.0,0.0,Infinity,Infinity,-0.0,-0.0 ....
提前感谢您的帮助。
英文:
I have an array namely “real”. it has a vector of double numbers. I am trying to create an INDArray based on my vector.
my code is below :
double real_d = (double) ArrBD.get(0);
INDArray real = Nd4j.create(real_d);
It works but unfortunately, it converts big numbers to infinity and small numbers to zero.
Here you can see the double array:
[0.0, 5.911259568298103E-306, -1.8401529637727614E-221, 1.7562463582928743E-268, 2.7206514809021945E-133, 4.583815262762733E90, 2.5637698710586 ....
and here the data of INDArray:
[0.0,0.0,-0.0,0.0,0.0,Infinity,Infinity,-0.0,-0.0 ....
I appreciate your help in advance
答案1
得分: 0
如果您希望获得更高的精度,您需要设置数据类型。就像NumPy或任何其他处理ndarrays的数学库一样,如果您使用浮点数,您将获得降低的精度。这是这些库的正常属性,仅仅是由于浮点数的工作原理。
创建ndarray时,您可以首先指定数据类型,或者手动创建数据缓冲区。
英文:
If you want more precision, you have to set the data type. Just like numpy or any other math library that works with ndarrays, if you have floats you will get reduced precision. This is a normal property of any of these libraries just due to how floating point numbers work.
When creating an ndarray, you can specify the data type first or create a data buffer manually.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论