Increasing precision of numpy.dot (python)

前端 未结 1 1992
南旧
南旧 2021-01-21 11:50

I\'m attempting to simulate a certain physical system. In order to propagate solutions I need to be able to multiply matrices of determinant = 1 which describe each part of the

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-21 12:47

    All Floating point operations have limited precision and errors do accumulate. You need to decide how much precision is "good enough" or how much error accumulation is "negligible". If float64 is not precise enough for you, try float128. You can find out the precision of the float types like this:

    In [83]: np.finfo(np.float32).eps
    Out[83]: 1.1920929e-07
    
    In [84]: np.finfo(np.float64).eps
    Out[84]: 2.2204460492503131e-16
    
    In [85]: np.finfo(np.float128).eps
    Out[85]: 1.084202172485504434e-19
    

    Here is a lot more info about floating point arithmetic: What Every Computer Scientist Should Know About Floating-Point Arithmetic

    0 讨论(0)
提交回复
热议问题