def choice_action_by_probs(probs=(<NUM_LIT:0.5>, <NUM_LIT:0.5>), action_list=None):
if action_list is None:<EOL><INDENT>n_action = len(probs)<EOL>action_list = np.arange(n_action)<EOL><DEDENT>else:<EOL><INDENT>if len(action_list) != len(probs):<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT><DEDENT>return np.random.choice(action_list, p=probs)<EOL>
Choice and return an an action by given the action probability distribution.

    Parameters
    ------------
    probs : list of float.
        The probability distribution of all actions.
    action_list : None or a list of int or others
        A list of action in integer, string or others. If None, returns an integer range between 0 and len(probs)-1.

    Returns
    --------
    float int or str
        The chosen action.

    Examples
    ----------
    >>> for _ in range(5):
    >>>     a = choice_action_by_probs([0.2, 0.4, 0.4])
    >>>     print(a)
    0
    1
    1
    2
    1
    >>> for _ in range(3):
    >>>     a = choice_action_by_probs([0.5, 0.5], ['a', 'b'])
    >>>     print(a)
    a
    b
    b