Loop over multi-dimensional array optimization

I did try using @views. It used less memory, but actually ran slower.