I would like to write an algorithm that calculates the sum of the elements in a 3*3-window of a 3D array without the value of the center of my window
For instance, for the input A :
A1 = np.array([[1,1,0],[0,0,0],[0,0,0]])
A2 = np.array([[0,0,0],[0,1,0],[0,0,0]])
A3 = np.array([[0,0,0],[0,0,0],[0,0,1]])
A = np.array ([A1,A2,A3])
I would like to obtain the output B:
([[1,1,0],[0,0,0],[0,0,0]])
([[0,0,0],[0,3,0],[0,0,0]])
([[0,0,0],[0,0,0],[0,0,1]])
So I wrote these pieces of code
Neighborhood = np.ones((3,3,3))
Neighborhood[1,1,1]=0 # take off the center
B1 = scipy.ndimage.generic_filter(A,np.sum,footprint = Neighborhood, origin =(1,1,1) )
B2 = scipy.ndimage.convolve(A,Neighborhood)
But neither B1 nor B2 give the answer I want Would you help me undestand why and how do I fix it ?