# tf_agents.utils.common.index_with_actions

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/common.py#L368-L412) |

Index into q_values using actions.

    tf_agents.utils.common.index_with_actions(
        q_values, actions, multi_dim_actions=False
    )

> [!NOTE]
> **Note:** this supports multiple outer dimensions (e.g. time, batch etc).

<br />

<br />

<br />

| ## Args ||
|---|---|
| `q_values` | A float tensor of shape \[outer_dim1, ... outer_dimK, action_dim1, ..., action_dimJ\]. |
| `actions` | An int tensor of shape \[outer_dim1, ... outer_dimK\] if multi_dim_actions=False \[outer_dim1, ... outer_dimK, J\] if multi_dim_actions=True I.e. in the multidimensional case, actions\[outer_dim1, ... outer_dimK\] is a vector \[actions_1, ..., actions_J\] where each element actions_j is an action in the range \[0, num_actions_j). While in the single dimensional case, actions\[outer_dim1, ... outer_dimK\] is a scalar. |
| `multi_dim_actions` | whether the actions are multidimensional. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A \[outer_dim1, ... outer_dimK\] tensor of q_values for the given actions. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If actions have unknown rank. |

<br />