Write functions that square or cube all the elements in a given 1D or 2D array. Also write a general "map" function for a 1D array.