def fold_lr(F):
    """
    Takes an unfolded two locus spectrum and folds based on left/right allele
    """
    ns = len(F[:, (0), (0)]) - 1
    for ii in range(ns + 1):
        for jj in range(ns + 1):
            for kk in range(ns + 1):
                if F.mask[ii, jj, kk]:
                    continue
                if kk > jj:
                    F[ii, kk, jj] += F[ii, jj, kk]
                    F[ii, jj, kk] = 0
                    F.mask[ii, jj, kk] = True
    return F
