Optimize N-dimensional arrays