I want to output the IoU as requested in the below question in python. Is there any way to do it in constant time?