# A Neural Network fully-coded in Numpy and Tensorflow

## Super simple, can’t be any easier, code provided

In a previous post, we explained the mechanics behind Neural networks. In this post we will show a basic implementation in pure Numpy, and in TensorFlow.

As we previously explain, neural networks execution have 4 main steps:

1. Forward step (where we go from inputs to outputs)
2. Loss function (where we compare the calculated outputs with real outputs)
3. Backward step (where we calculate the first delta at the loss function and then back-propagate)
4. Optimization step (where we update the internal weights with deltas and learning rate)

The easiest way to do a full working example, is to take only one operator (matrix multiplication), one loss function (RMSE), one optimizer(gradient descent) and execute a full running example.

`def forwardMult(A,B):    return np.matmul(A,B) def backwardMult(dC,A,B,dA,dB):    dA += np.matmul(dC,np.matrix.transpose(B))    dB += np.matmul(np.matrix.transpose(A),dC)    #Loss example in forward and backward (RMSE)def forwardloss(predictedOutput,realOutput):    if(predictedOutput.shape == realOutput.shape):        loss = np.mean( 0.5*np.square(predictedOutput - realOutput))           else :        print("Shape of arrays not the same")    return lossdef backwardloss(predictedOutput,realOutput):    if(predictedOutput.shape == realOutput.shape):        deltaOutput = (predictedOutput - realOutput)/predictedOutput.size    else :        print("Shape of arrays not the same")    return deltaOutput#Optimizer example (SGD)def updateweights(W,dW,learningRate):    W -= learningRate * dW`

The full code can be found in Numpy here, in Tensorflow here, and a comparision between both here.

The repo is made available on GitHub as a tutorial to understand how a neural network works.

In case you still have any questions, please do not hesitate to comment or contact me at: assaad.moawad@datathings.com

Written by

## More From Medium

### Dense layers explained in a simple way

Oct 8, 2019 · 2 min read

### Linear layers explained in a simple way

Oct 1, 2019 · 5 min read

### Dimensions and degrees of freedom

Mar 6, 2019 · 4 min read

#### 130

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just \$5/month. Upgrade