---
title: "ClikaRT::ops::index_select"
sidebar_label: "index_select"
description: "Select whole rows of input at index positions along dim. Output = input's shape with the dim extent replaced by index's length; rows may repeat and appear in any order."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## index\_select() {#index_select}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`index_select`**(<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `input`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;`int64_t` `dim`,<br />
&nbsp;&nbsp;&nbsp;&nbsp;[`Tensor`](../Tensor.md) `index`<br />
)

</div>

Select whole rows of `input` at [`index`](./index-fn.md#index) positions along `dim`.

Output = `input`'s shape with the `dim` extent replaced by [`index`](./index-fn.md#index)'s length; rows may repeat and appear in any order. [`index`](./index-fn.md#index) is 1-D `Int32`/`Int64`; prefer `Int32` where the extents allow (half the index bytes).

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) when `dim` is out of range or the index dtype is wrong (`code_name()` carries the reason).

**Returns:** a new tensor: `input`'s shape with `dim` resized to [`index`](./index-fn.md#index)'s length.

```cpp
auto rows = ClikaRT::ops::index_select(table, 0, ids);  // [n_ids, ..]
```

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 2570

</div>
