I have a 2d numpy array x of size 11 x 20000. The rows mostly consists of small decimal values (with some occasional 0s). I want to take the product of only the non-zero values. I can easily do this by using numpy.prod:
y = numpy.prod(x, axis = 1, where = arr > 0)
y has only 11 elements that is the product of non-zero elements of x's rows. But, after printing the contents of y, I find out that in some cases every element of y is becoming 0. I suppose it's a precision issue as y's value in becoming less that some threshold that numpy can't represent. So use the highest precision, I change the np.prod as follows:
y = np.prod(x, axis = 1, where = arr > 0, dtype = np.longdouble)
But the result is the same. I then print out the implementation of np.longdouble:
print(np.finfo(np.longoduble))
>>> Machine parameters for float64
---------------------------------------------------------------
precision = 15 resolution = 1.0000000000000001e-15
machep = -52 eps = 2.2204460492503131e-16
negep = -53 epsneg = 1.1102230246251565e-16
minexp = -1022 tiny = 2.2250738585072014e-308
maxexp = 1024 max = 1.7976931348623157e+308
nexp = 11 min = -max
---------------------------------------------------------------
So the least value numpy can represent on my machine is e-308. But on my friend's computer the same command prints:
Now I suppose I do not have the necessary hardware support for extended precision on my machine. But when I run the following C++ code on my machine:
#include <iostream>
#include <limits>
using namespace std;
int main(int argc, char const *argv[])
{
cout << numeric_limits<long double>::min() << '\n';
return 0;
}
Output:
3.3621e-4932
So, clearly I have hardware support to access much lower values than e-308. My question is, how can I use float128 implementation for np.longdouble on my machine?
Additional information:
numpy version: 1.18.1
python version: 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]
