<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _do_scale_fit(freqs, signal, model, w=None):
 """ Perform a round of fitting to deal with over or under-estimation. Scales curve on y-axis but preserves shape. Parameters freqs : array signal : array The signal that the model is being fit to model : array The model being scaled w : array weighting function Returns ------- scalefac : array of len(signal) the scaling factor for each transient scalemodel : array of model.shape the scaled model """

   scalefac = np.empty(model.shape[0])
   scalemodel = np.empty((model.shape[0], np.real(model).shape[1]))
   scalesignal = np.empty((signal.shape[0], np.real(signal).shape[1]))
   for ii, xx in enumerate(signal): # per transient
      scalesignal[ii] = np.real(xx)
#      ratio = np.empty(scalesignal[ii].shape[0])
#      for ppm, trans in enumerate(scalesignal[ii]):
#          ratio[ppm] = trans/model[ii][ppm]
#      scalefac[ii] = np.mean(ratio,0)
      scalefac[ii] = np.nanmean(scalesignal[ii],0)/np.nanmean(model[ii],0)
      scalemodel[ii] = scalefac[ii] * model[ii]
   return scalefac, scalemodel