def _finalize_tavgs(tavgs):
    """Finalize averages by dividing by sample size."""
    count = tavgs["counter"]
    del tavgs["counter"]
    for varname in tavgs:
        if varname == "counter":
            continue
        if len(tavgs[varname].shape) == 4:
            tavgs[varname][:,:,:,:] /= count
        elif len(tavgs[varname].shape) == 3:
            tavgs[varname][:,:,:] /= count
        elif len(tavgs[varname].shape) == 2:
            tavgs[varname][:,:] /= count
    return tavgs