Premium problem132. Pairwise IoU Matrix Between Box Sets

Medium Locked

A is (n, 4) and B is (m, 4), both boxes in [x1, y1, x2, y2] format. Return the (n, m) matrix of pairwise intersection-over-union values, with 0 where boxes do not overlap.

Input

A =
[[ 0.  0.  2.  2.]
 [10. 10. 12. 12.]]
B =
[[1. 1. 3. 3.]
 [0. 0. 2. 2.]]

Output

[[0.14285714 1.        ]
 [0.         0.        ]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)