def set_transitions(self, mat):
if isinstance(mat, dict):<EOL><INDENT>for key, value in mat.items():<EOL><INDENT>probs = list(value.values())<EOL>if key not in self.g.node:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>elif len(self.out_edges[key]) > <NUM_LIT:0> and not np.isclose(sum(probs), <NUM_LIT:1>):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>elif (np.array(probs) < <NUM_LIT:0>).any():<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>for k, e in enumerate(sorted(self.g.out_edges(key))):<EOL><INDENT>self._route_probs[key][k] = value.get(e[<NUM_LIT:1>], <NUM_LIT:0>)<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(mat, np.ndarray):<EOL><INDENT>non_terminal = np.array([self.g.out_degree(v) > <NUM_LIT:0> for v in self.g.nodes()])<EOL>if mat.shape != (self.nV, self.nV):<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>").format(self.nV, self.nV)<EOL>raise ValueError(msg)<EOL><DEDENT>elif not np.allclose(np.sum(mat[non_terminal, :], axis=<NUM_LIT:1>), <NUM_LIT:1>):<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>elif (mat < <NUM_LIT:0>).any():<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>for k in range(self.nV):<EOL><INDENT>for j, e in enumerate(sorted(self.g.out_edges(k))):<EOL><INDENT>self._route_probs[k][j] = mat[k, e[<NUM_LIT:1>]]<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>
Change the routing transitions probabilities for the
        network.

        Parameters
        ----------
        mat : dict or :class:`~numpy.ndarray`
            A transition routing matrix or transition dictionary. If
            passed a dictionary, the keys are source vertex indices and
            the values are dictionaries with target vertex indicies
            as the keys and the probabilities of routing from the
            source to the target as the values.

        Raises
        ------
        ValueError
            A :exc:`.ValueError` is raised if: the keys in the dict
            don't match with a vertex index in the graph; or if the
            :class:`~numpy.ndarray` is passed with the wrong shape,
            must be (``num_vertices``, ``num_vertices``); or the values
            passed are not probabilities (for each vertex they are
            positive and sum to 1);
        TypeError
            A :exc:`.TypeError` is raised if mat is not a dict or
            :class:`~numpy.ndarray`.

        Examples
        --------
        The default transition matrix is every out edge being equally
        likely:

        >>> import queueing_tool as qt
        >>> adjacency = {
        ...     0: [2],
        ...     1: [2, 3],
        ...     2: [0, 1, 2, 4],
        ...     3: [1],
        ...     4: [2],
        ... }
        >>> g = qt.adjacency2graph(adjacency)
        >>> net = qt.QueueNetwork(g)
        >>> net.transitions(False)  # doctest: +ELLIPSIS
        ...                         # doctest: +NORMALIZE_WHITESPACE
        {0: {2: 1.0},
         1: {2: 0.5, 3: 0.5},
         2: {0: 0.25, 1: 0.25, 2: 0.25, 4: 0.25},
         3: {1: 1.0},
         4: {2: 1.0}}

        If you want to change only one vertex's transition
        probabilities, you can do so with the following:

        >>> net.set_transitions({1 : {2: 0.75, 3: 0.25}})
        >>> net.transitions(False)  # doctest: +ELLIPSIS
        ...                         # doctest: +NORMALIZE_WHITESPACE
        {0: {2: 1.0},
         1: {2: 0.75, 3: 0.25},
         2: {0: 0.25, 1: 0.25, 2: 0.25, 4: 0.25},
         3: {1: 1.0},
         4: {2: 1.0}}

        One can generate a transition matrix using
        :func:`.generate_transition_matrix`. You can change all
        transition probabilities with an :class:`~numpy.ndarray`:

        >>> mat = qt.generate_transition_matrix(g, seed=10)
        >>> net.set_transitions(mat)
        >>> net.transitions(False)  # doctest: +ELLIPSIS
        ...                         # doctest: +NORMALIZE_WHITESPACE
        {0: {2: 1.0},
         1: {2: 0.962..., 3: 0.037...},
         2: {0: 0.301..., 1: 0.353..., 2: 0.235..., 4: 0.108...},
         3: {1: 1.0},
         4: {2: 1.0}}

        See Also
        --------
        :meth:`.transitions` : Return the current routing
            probabilities.
        :func:`.generate_transition_matrix` : Generate a random routing
            matrix.