I'm confused by the indexing of the filter array for scipy.ndimage.convolve
.
The simplest example, Identity works as I expected -- I get the same matrix back.
But I thought that a filter like:
0, 0, 0
0, 0, 1
0, 0, 0
Should give me the original matrix shifted one column left, with zero padding on the right edge.
Instead, the result is shifting the original matrix to the right, adding zero padding to the left column.
Similar results for the shifts in the other dimension. Up seems down, and left seems right.
This makes me think I've got some fundamental misunderstanding about numpy indexing (which is quite possible) or what a convolution does (I think it's the sum of the products of each cell of the filter times the corresponding cell of the matrix, with the filter centered like a bullseye on the relevant cell of the matrix)
from scipy import ndimage
a = np.array([[1, 2, 0, 0],
[5, 3, 7, 4],
[0, 5, 1, 7],
[9, 3, 0, 0]])
#k = np.array([[0,0,0],[0,1,0],[0,0,0]]) #identity
#expect: each cell in a' = its right neighbor in a
#actual: each cell in a' = its LEFT neighbor in a
k = np.array([[0,0,0],[0,0,1],[0,0,0]])
cvo = ndimage.convolve(a, k, mode='constant', cval=0.0)
cvo