built in function for computing overlap in Python

后端 未结 4 1336
囚心锁ツ
囚心锁ツ 2020-12-09 08:33

is there a built in function to compute the overlap between two discrete intervals, e.g. the overlap between [10, 15] and [20, 38]? In that case the overlap is 0. If it\'s

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 09:04

    Check out pyinterval http://code.google.com/p/pyinterval/

    import interval
    x=interval.interval[10, 15]
    y=interval.interval[20, 38]
    z=interval.interval[12,18]
    
    print(x & y)
    # interval()
    print(x & z)
    # interval([12.0, 15.0])
    

提交回复
热议问题