This is not a method for checking containment (like python in).
The typical use case for this operation is "binning", "bucketing", or
"discretizing". The values are assigned to bucket-indices based on the
edges listed in sorted_sequence. This operation
returns the bucket-index for each value.
The axis is not settable for this operation. It always operates on the
innermost dimension (axis=-1). The operation will accept any number of
outer dimensions. Here it is applied to the rows of a matrix:
'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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.searchsorted\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/array_ops.py#L6050-L6130) |\n\nSearches for where a value would go in a sorted sequence.\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`](https://www.tensorflow.org/api_docs/python/tf/searchsorted)\n\n\u003cbr /\u003e\n\n tf.searchsorted(\n sorted_sequence,\n values,\n side='left',\n out_type=../tf/dtypes#int32,\n name=None\n )\n\nThis is not a method for checking containment (like python `in`).\n\nThe typical use case for this operation is \"binning\", \"bucketing\", or\n\"discretizing\". The `values` are assigned to bucket-indices based on the\n**edges** listed in `sorted_sequence`. This operation\nreturns the bucket-index for each value. \n\n edges = [-1, 3.3, 9.1, 10.0]\n values = [0.0, 4.1, 12.0]\n tf.searchsorted(edges, values).numpy()\n array([1, 2, 4], dtype=int32)\n\nThe `side` argument controls which index is returned if a value lands exactly\non an edge: \n\n seq = [0, 3, 9, 10, 10]\n values = [0, 4, 10]\n tf.searchsorted(seq, values).numpy()\n array([0, 2, 3], dtype=int32)\n tf.searchsorted(seq, values, side=\"right\").numpy()\n array([1, 2, 5], dtype=int32)\n\nThe `axis` is not settable for this operation. It always operates on the\ninnermost dimension (`axis=-1`). The operation will accept any number of\nouter dimensions. Here it is applied to the rows of a matrix: \n\n sorted_sequence = [[0., 3., 8., 9., 10.],\n [1., 2., 3., 4., 5.]]\n values = [[9.8, 2.1, 4.3],\n [0.1, 6.6, 4.5, ]]\n tf.searchsorted(sorted_sequence, values).numpy()\n array([[4, 1, 2],\n [0, 5, 4]], dtype=int32)\n\n| **Note:** This operation assumes that `sorted_sequence` **is sorted** along the innermost axis, maybe using `tf.sort(..., axis=-1)`. **If the sequence is not\n| sorted, no error is raised** and the content of the returned tensor is not well defined.\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"]]