def get_reorg_matrix(m, m_size, transition_state_nb):
    """
    Reorder the matrix to only keep the rows with the transition states
    By storing the new order in an array, we can have a mapping between new pos (idx) and old pos (value)
    For example reorg_states = [2,3,1,0] means the first new row/col was in position 2 before, and so on...

    :param m: the original matrix
    :param m_size: the original matrix size
    :param transition_state_nb: the number of transision states
    :return: a QR matrix of the size transition_state_nb*m_size (because we have the transition states first here)
    """

    # Get the new position for the transision and the final states
    transition_states = [i for i in range(m_size) if sum(m[i]) > 0]
    final_states = [i for i in range(m_size) if sum(m[i]) == 0]
    reorg_states = transition_states + final_states

    # Init an empty matrix  the same size of RQ
    reorg_m = [[0 for _ in range(m_size)] for _ in range(transition_state_nb)]

    # for each transition row, we rearrange them
    for i in range(transition_state_nb):
        for j in range(m_size):
            reorg_m[i][j] = m[reorg_states[i]][reorg_states[j]]

    return reorg_m