Conv1d for horizontal gradient

Hello,

I need to extract the horizontal gradient of a binarized image.
As a toy example, consider one single row of the image of length 10
What I do is:

row = np.array([0,1,1,1,1,0,1,1,1,0]).reshape(1,1,10)
row = torch.Tensor(row)

m = nn.Conv1d(1, 1, 2, stride=1)
dx=np.array([1, -1])
m.weight=nn.Parameter(torch.from_numpy(dx).float().unsqueeze(0).unsqueeze(0))
output = m(row)

As output, I would expect:

[ 0,  1,  0,  0,  0, -1,  1,  0,  0, -1,  0]

But I am actually having random values that change at every run…

Why so?

PROBLEM SOLVED: I must set bias = False