I have a python 3D list. Making it more clear, a list of list where each list is the four corner coordinate of a box. I have to filter all the boxes which are smaller than some given size.
Let us suppose this is the python list.
box = [[[4, 4], [4, 8], [8, 8], [8, 4]],
[[8, 8], [8, 16], [16, 16], [16, 8]],
[[20,16],[20,20],[24,20],[24,16]]
...
]
I have to filter all boxes with length and breadth less than or equal to 5.
filtered_box = [[[4, 4], [4, 8], [8, 8], [8, 4]],
[[20,16],[20,20],[24,20],[24,16]]
...
]
This is my current code
filtered_box = []
for c in box:
min_x, min_y = c[0]
max_x, max_y = c[2]
if max_x - min_x <= 5 & min_y - max_y <= 5:
filtered_box.append(c)
This is working good but I need a more optimized solution. It can use numpy and convert back to python list or use the native python operations on list. I am using Python 3.