This code was written based on the book "Make your own neural network" by Tariq Rashid, but with a slight change as described in the following blog post: https://medium.com/p/f839bf7f3fe2
In summary, the expression on line 51 was replaced with the expression on line 52, according to the reasoning in the mentioned blog post. A seed for the RNG was added to in order to better compare performances of the two expressions. The original expression performed around 1% better in the basic tests. For more information, check out the blog post mentioned above.