Rewrote gradient descent to use Apply for scalar matrix multiplication.