def thin_chains(chains, thin_factor):
    """ A function to thin an emcee or PTemcee chain (or blob)

    Parameters
    ----------
    chains : ndarray
        Chain output from emcee in 3 dimensions (or 4 dimensions if PTemcee)
    thin_factor : int
        Factor to reduce the array size by

    Returns
    -------
    chains : ndarray
        Thinned, 3 dimensional array of chains

    """
    if chains.ndim == 4:
        return chains[:, :, ::thin_factor, :]
    else:
        return chains[:, ::thin_factor, :]
