Do you care about the actual accuracy of the result or how to return the same numbers from your two calculations?
If you only need the same numbers, you can use np.around() to round the results to some suitable number of decimal places. However, by doing this, you will reduce the accuracy of the result.
If you really want to more accurately calculate the result, you can try using the np.longdouble type for your input array, which , depending on your architecture and compiler , can give you a floating point representation of 80 or 128 bits, rather than the standard 64-bit np.double *.
You can compare the approximate number of decimal places of precision with np.finfo :
print np.finfo(np.double).precision # 15 print np.finfo(np.longdouble).precision # 18
Note that not all numpy functions will support the long double part - some will double it.
* However, some compilers (such as Microsoft Visual C ++) will always consider long double as synonyms for double , in which case there will be no difference between the accuracy of np.longdouble and np.double .
ali_m
source share