tf.searchsorted

View source on GitHub

Searches input tensor for values on the innermost dimension.

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]]

Args:

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.

Raises: