makeNd function

Ensure/collapse an array into n dimensions and restore the old dimensions