I am importing some numbers into python from a matlab "mat" file version 5 and they have a different precision.
This is the python Code:
output_data = numpy.matlab.loadmat( ( path ), mat_dtype=True )
print(output_data)
Python3 output: -0.0030967733388058967-> 20 numbers or digits
Matlab output: -0.00309677333880590 -> 18 " "
Why would python and matlab have different precisions?
Both MATLAB and Python/Numpy use the same floating-point representation by default, 64-bit floats (double precision). How this is stored is dictated by your CPU, not by the program (the program basically gets to choose between 32, 64 and 80 bit floats, which are the representations understood by the CPU in your average PC).
The difference that you see is how the programs choose to display the numbers. The internal representation is identical.
If the difference between these numbers, as displayed, matter to your application, you are doing it wrong. Floating-point computations are imprecise by definition, you cannot count on those last few digits to be meaningful.
Hope the answer in this link helps:
https://ww2.mathworks.cn/matlabcentral/answers/77455-raising-to-the-power-of-large-numbers-is-giving-me-the-wrong-answer
To quote the person who answered the question:
In general, MATLAB uses double-precision, which roughly means that you can expect 16 digits of precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With