Skip to main content

3.2- Multi Neurons Matrix

Lets solve the same thing using matrix way

weightinputbias
Weights=[neuron1=>neuron2=>][123212]Weights=\begin{bmatrix}neuron1=>\\neuron2=>\end{bmatrix}\begin{bmatrix} 1&2&3\\2&1&2\end{bmatrix}inputs=[2 3 4]inputs=\begin{bmatrix}2 \ 3 \ 4\end{bmatrix}bias=[1 2]bias=\begin{bmatrix}1\ 2 \end{bmatrix}
Substitute:
y=[123212][234]+[12]y= \begin{bmatrix} 1&2&3\\ 2&1&2 \end{bmatrix} \begin{bmatrix} 2\\ 3\\ 4 \end{bmatrix} + \begin{bmatrix} 1\\ 2 \end{bmatrix}

Matrix multiplication gives:

y=[(1)(2)+(2)(3)+(3)(4) (2)(2)+(1)(3)+(2)(4)]+[1 2]y= \begin{bmatrix} (1)(2)+(2)(3)+(3)(4)\ (2)(2)+(1)(3)+(2)(4) \end{bmatrix} + \begin{bmatrix} 1\ 2 \end{bmatrix} y=[20 15]+[1 2]y= \begin{bmatrix} 20\ 15 \end{bmatrix} + \begin{bmatrix} 1\ 2 \end{bmatrix}

Therefore:

y=[21 17]\boxed{ y= \begin{bmatrix} 21\ 17 \end{bmatrix}}

The Important Connection​

Expanded:

y1=w11x1+w12x2+w13x3+b1y2=w21x1+w22x2+w23x3+b2\begin{aligned} y_1&=w_{11}x_1+w_{12}x_2+w_{13}x_3+b_1\\ y_2&=w_{21}x_1+w_{22}x_2+w_{23}x_3+b_2 \end{aligned}

Contracted:

y=Wx+b\boxed{y=Wx+b}

The matrix form is simply a compact way of writing all the individual neuron calculations together.

import numpy as np

x = np.array([2, 3, 4])

W = np.array([
[1, 2, 3],
[2, 1, 1]
])

b = np.array([5, 2])

y = W @ x + b

print(y)