I've been using numpy indexing for a while now. But I've only ever had to select basic shapes such as rectangles or discs
However, I now need to be able to select more arbitrary shapes and I can't find a good way of doing this. Ideally, I would like to be able to give a list of corners and for all of the indices contained within those corners to be selected. We can assume the given shape is convex
For example, given an array filled with zeroes of shape (10, 10), by trying to set the values within the corners ((2,2), (6,3), (4,8) and (7,9)) to 1 this would return a mask like such
[[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 1., 1., 1., 0., 0., 0., 0., 0.],
[0., 0., 1., 1., 1., 1., 0., 0., 0., 0.],
[0., 0., 1., 1., 1., 1., 1., 1., 1., 0.],
[0., 0., 0., 1., 1., 1., 1., 1., 1., 0.],
[0., 0., 0., 1., 1., 1., 1., 1., 1., 1.],
[0., 0., 0., 0., 0., 0., 1., 1., 1., 1.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]
Now one of the problems is that there generally is no unique solution to this problem, but taking a plausible one is good enough for me. I can't think of a way of doing this using numpy however, as only basic slicings and clear mathematical equations seem to be supported.
Has anyone ever run into such a challenge? Do I have to resort to more traditional python for loops?