I copied the entire body of this function from np.apply_over_axes.  I don't mind cleaning it up a bit, but I don't want to introduce spurious differences between the two functions.  Should I reformat np.apply_over_axes as well?