Trying to learn how to implement a single Neuron
I have this code in Pytorch but cant get it to work. I have it working with Numpy as return (X.T * W).sum(axis=1) + B 

But with Pytorch I keep getting this error...


def neural_network_neurons(W, B, X):

    W = W.view(W.size(0), -1)
    z1 =  torch.matmul(X, W) + B
    return ReLU(z1)

# --------------------------------------------------
W = torch.tensor([[1.2, 0.3, 0.1], [.01, 2.1, 0.7]])
B = torch.tensor([2.1, 0.89])
X = torch.tensor([0.3, 6.8, 0.59])

neural_network_neurons(W, B, X)

---------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-21-8a5d3a425c16&gt; in &lt;module&gt;
      4 X = torch.tensor([0.3, 6.8, 0.59])
      5 
----&gt; 6 neural_network_neurons(W, B, X)

&lt;ipython-input-20-7450924eb4a5&gt; in neural_network_neurons(W, B, X)
      5     ###
      6     W = W.view(W.size(0), -1)
----&gt; 7     z1 =  torch.matmul(X, W) + B
      8     return ReLU(z1)
      9     #return (X.T * W).sum(axis=1) + B

RuntimeError: size mismatch, m1: [1 x 3], m2: [2 x 3] at
/pytorch/aten/src/TH/generic/THTensorMath.cpp:197



You have the wrong orientation for W: you defined a 2x3 matrix, but your algorithm requires a 3x2.  Try W.T instead?
