Transform a 1d array into a 2d array