Not sure whats the best way to title this question, but basically I would like to fill an existing numpy array with a value, based on the location provided and a specified distance. Assuming going diagonally is not valid.
For example, lets say we have an array with just 0s.
[[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 0]]
If I want (2,2) as the location with distance 1, it would fill the matrix with value 1, in the location that has distance one from the location provided, including itself. Thus the matrix would look like:
[[0 0 0 0 0]
[0 0 1 0 0]
[0 1 1 1 0]
[0 0 1 0 0]
[0 0 0 0 0]]
And if I provided a distance of 2, it would look like:
[[0 0 1 0 0]
[0 1 1 1 0]
[1 1 1 1 1]
[0 1 1 1 0]
[0 0 1 0 0]]
Basically everything within a distance of 2 from the location will be filled with the value 1. Assuming diagonal movement is not valid.
I also would like to support wrapping, where if the neighboring elements are out of bounds, it will wrap around.
For example, if the location provided is (4,4) with distance 1, the matrix should look like so:
[[0 0 0 0 1]
[0 0 0 0 0]
[0 0 0 0 0]
[0 0 0 0 1]
[1 0 0 1 1]]
I tried using np.ogrid along with a mask of where the 1's will be true but cant seem to get it working.