Vectorized implementation of backpropagation