If vector is a matrix then why weights assigned are different for Perceptron and Sigmoid models?

If vector is also a matrix as a matrix can have one row or one column then how do they differ? I want to understand why weights for Sigmoid model is assigned as self.w = np.random.randn(1, X.shape[1]) whereas for Perceptron model it is self.w = np.random.randn(X.shape[1]).

Is it correct to assign weights for sigmoid as self.w = np.random.randn(X.shape[1])?

In the following code snippet, V is of 1 dimension and Q is of 2 dimensions.

X = np.asarray([
                [2.5, 2.5], [4, -1],
                [2, 4], [1, 5]
                ])

# if this is one-row vector or matrix
Q = np.random.randn(1, X.shape[1])

# can this is also be called a matrix with one-row or as row vector?
V = np.random.randn(X.shape[1])

# shape: (4, 2), size:  8, dimension: 2
print(X.shape, X.size, X.ndim)

# shape: (1, 2), size:  2, dimension: 2
print(Q.shape, Q.size, Q.ndim)

# shape: (2,), size:  2, dimension: 1
print(V.shape, V.size, V.ndim)

Hi @4deep.prk,
There’s no such rule to distinguish between to use of these two.
Just to clarify, in sigmoid and perceptron, different datasets are used. Due to which the shape of ‘Y’ is different in these.
We’re using different shapes of W, just to match the ‘Y’ label shape in order to match the shape of ‘Y_pred’ and ‘Y’.

Please take a look at these points in the code, i hope you’ll get to understand what I’m trying to say.

1 Like

Thank you very much. I was confused by the broadcasting between input features and weight vector.

In case of one row vector as 2D array self.w = np.random.randn(1, X.shape[1]) the transpose of weight vector return np.dot(x, self.w.T) + self.b is needed.

Whereas in this case of vector as 1D array self.w = np.random.randn(X.shape[1]) the transpose is not needed np.dot(x, self.w) + self.b.