How do I find the difference between two values without knowing which is larger?

前端 未结 11 2192
借酒劲吻你
借酒劲吻你 2020-12-11 14:22

I was wondering if there was a function built into Python that can determine the distance between two rational numbers but without me telling it which number is larger. e.g.

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 14:54

    If you have an array, you can also use numpy.diff:

    import numpy as np
    a = [1,5,6,8]
    np.diff(a)
    Out: array([4, 1, 2])
    

提交回复
热议问题