tf.searchsorted
Stay organized with collections
Save and categorize content based on your preferences.
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 |
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 .
|
name
|
Optional name for the operation.
|
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 |
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.searchsorted\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/searchsorted) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/array_ops.py#L4477-L4535) |\n\nSearches input tensor for values on the innermost dimension.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.searchsorted`](/api_docs/python/tf/searchsorted)\n\n\u003cbr /\u003e\n\n tf.searchsorted(\n sorted_sequence, values, side='left', out_type=tf.dtypes.int32, name=None\n )\n\nA 2-D example: \n\n sorted_sequence = [[0, 3, 9, 9, 10],\n [1, 2, 3, 4, 5]]\n values = [[2, 4, 9],\n [0, 2, 6]]\n\n result = searchsorted(sorted_sequence, values, side=\"left\")\n\n result == [[1, 2, 2],\n [0, 1, 5]]\n\n result = searchsorted(sorted_sequence, values, side=\"right\")\n\n result == [[1, 2, 4],\n [0, 2, 5]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|----------------------------------------------------------------------------------|\n| `sorted_sequence` | N-D `Tensor` containing a sorted sequence. |\n| `values` | N-D `Tensor` containing the search values. |\n| `side` | 'left' or 'right'; 'left' corresponds to lower_bound and 'right' to upper_bound. |\n| `out_type` | The output type (`int32` or `int64`). Default is [`tf.int32`](../tf#int32). |\n| `name` | Optional name for the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| 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. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If the last dimension of `sorted_sequence \u003e= 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. |\n\n\u003cbr /\u003e"]]