# tf.searchsorted

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/searchsorted) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/array_ops.py#L4477-L4535) |

Searches input tensor for values on the innermost dimension.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.searchsorted`](https://www.tensorflow.org/api_docs/python/tf/searchsorted)

<br />

    tf.searchsorted(
        sorted_sequence, values, side='left', out_type=tf.dtypes.int32, name=None
    )

A 2-D example:

      sorted_sequence = [[0, 3, 9, 9, 10],
                         [1, 2, 3, 4, 5]]
      values = [[2, 4, 9],
                [0, 2, 6]]

      result = searchsorted(sorted_sequence, values, side="left")

      result == [[1, 2, 2],
                 [0, 1, 5]]

      result = searchsorted(sorted_sequence, values, side="right")

      result == [[1, 2, 4],
                 [0, 2, 5]]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `sorted_sequence` | N-D `Tensor` containing a sorted sequence. |
| `values` | N-D `Tensor` containing the search values. |
| `side` | 'left' or 'right'; 'left' corresponds to lower_bound and 'right' to upper_bound. |
| `out_type` | The output type (`int32` or `int64`). Default is [`tf.int32`](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf#int32). |
| `name` | Optional name for the operation. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| An N-D `Tensor` the size of values containing the result of applying either lower_bound or upper_bound (depending on side) to each value. The result is not a global index to the entire `Tensor`, but the index in the last dimension. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the last dimension of `sorted_sequence >= 2^31-1` elements. If the total size of values exceeds `2^31 - 1` elements. If the first `N-1` dimensions of the two tensors don't match. |

<br />