<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def is_ergodic(T, tol):
 """ checks if T is 'ergodic' Parameters T : scipy.sparse matrix Transition matrix tol : float tolerance Returns ------- Truth value : bool True, if # strongly connected components = 1 False, otherwise """

    if isdense(T):
        T = T.tocsr()
    if not is_transition_matrix(T, tol):
        raise ValueError("given matrix is not a valid transition matrix.")

    num_components = connected_components(T, directed=True, \
                                          connection='strong', \
                                          return_labels=False)

    return num_components == 1