def rinse(M, d=1e-14):
    """
    This function removes any entries in a list or array that 
    are closer to zero than d is. It is used in the gauss function
    to avoid division by near-zero values. By default d is set
    to be equal to 10^-14.
    """
    m = len(M)
    if type(M[0]) == list:
        n = len(M[0])
    else:
        for ind, x in enumerate(M):
            if abs(x) < d:
                M[ind] = 0
        return M
    for p in range(m):
        for q in range(n):
            if abs(M[p][q]) < d:
                M[p][q] = 0
    return M