xs = np.array([[0, 1, 0], [0, 0, 1], [0, 1, 1]]) * 1.0
ys = np.array([[0, 1], [1, 1]]) * 1.0
print(scipy.ndimage.convolve(xs, ys, mode='constant', cval=np.inf))
numpy template matching using matrix multiplications