Initialize an n-dimensional array with a specified function