Vectorizing across multiple examples

For-loop approach

If you have m training examples, in 2-layer NN, you will have

So if you are to do this in for-loop, you would write

for to :

   

   

   

   

vectorized implementation

A vector

Recall can be represented as a stacked columns of samples.

(1) is a dimentional matrix. The horizontal index corresponds to different training example. The vertical index corresponds to different features in the neural network.

A vector

can be also represented as a stacked columns of .

(2) is a dimentional matrix. The horizontal index corresponds to different training example. The vertical index corresponds to different nodes in the neural network.

A vector

can be also represented as a stacked columns of .

(3) is a dimentional matrix. The horizontal index corresponds to different training example. The vertical index corresponds to different nodes in the neural network.

So vectorizing implementation of neural network will be:

Justification for vectorized implementation

Assuming ,

so , ,

and

Vertical: number of features, Horizontal: number of training samples (n=3)

If you multiply with ,

, because input layer is ‘0’, so and