filt = np.zeros((3, 3))
filt[1, shift+1] = -1
filt[1, filt.shape[1] - 1] = 1

The above code generates a 3x3 filter that does a simple forward gradient. In order to do a simple correlation, I can do the following:
from scipy.signal import correlate2d
from scipy import misc
im = misc.imread('grascale.png') # a grayscale image
imout = correlate2d(im,filt,mode='same',boundary='symm')

The above code ensures the output is the same size of input ‘im’ and also symmetrically reuses the values to fill the boundary pixels during convolution. How can I do the same using conv2d in pytorch? Also, is it enough to set bias to false and weight.data to filt value?