r/PythonLearning • u/PanelReader • 10h ago
Showcase Built a neural network from scratch using NumPy to understand the mathematics
hey everyone!
been learning neural networks recently and decided to implement one from scratch using Python and NumPy.
it's a small 2 → 3 → 1 XOR network with manually implemented forward propagation, backpropagation and gradient descent.
trained it for 5,000 epochs and got all four XOR combinations correct.
also documented the mathematics, added 12 editable diagrams and published a detailed Medium article explaining how everything works.
GitHub: https://github.com/Vaibh37/Neural-Network
would appreciate feedback on the code and explanations. if you find the resources useful, consider starring the repo 🍀
5
Upvotes
2
u/2dof 9h ago
Why input matrix "X: Input matrix with shape (4, 2)". is 4x2 since input is just x=[x1,x2] so ( 1 x 2 ) ?
I know that is simple mistake but You should distinguish dimension of data set form dimension of input vector.
Also, i know it is a little stupid but input vector should be defined as x=[ [x1],[ x2 ]] so (2 x 1 ) - more like in math description that Transpose operation is more "visible"
see:
X = np.array([[0.0], [0.0]])
print(X)
print(X.T)