Solved by albanD in post #4 
              
              
                Ok. 
So you don’t actually want the gradient for x, only W right? 
I think the +1 difference in the size comes from the bias term that is often added in linear regression that you are missing when you do x*W only. 
You can either have another parameter of size 1 b and compute x*W + b. And now you ge…