You are given an nxn
ndarray M
and location (x, y)
and the goal is to shift the values such that c = (x, y)
is centered. Values that "fall outside" are removed and empty space is filled with zeros.
Example:
Input:
M =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
5 5 5 5 5
c = (0, 0)
Output:
0 0 0 0 0
0 0 0 0 0
0 0 1 1 1
0 0 2 2 2
0 0 3 3 3
c = (3, 4)
Output:
2 2 2 0 0
3 3 3 0 0
4 4 4 0 0
5 5 5 0 0
0 0 0 0 0
Is there any function for it in numpy/scipy or any other packages in python?
Thank you