tf.keras.ops.argsort
Stay organized with collections
Save and categorize content based on your preferences.
Returns the indices that would sort a tensor.
tf.keras.ops.argsort(
x, axis=-1
)
Args |
x
|
Input tensor.
|
axis
|
Axis along which to sort. Defaults to-1 (the last axis). If
None , the flattened tensor is used.
|
Returns |
Tensor of indices that sort x along the specified axis .
|
Examples:
One dimensional array:
x = keras.ops.array([3, 1, 2])
keras.ops.argsort(x)
array([1, 2, 0], dtype=int32)
Two-dimensional array:
>>> x = keras.ops.array([[0, 3], [3, 2], [4, 5]])
>>> x
array([[0, 3],
[3, 2],
[4, 5]], dtype=int32)
>>> keras.ops.argsort(x, axis=0)
array([[0, 1],
[1, 0],
[2, 2]], dtype=int32)
>>> keras.ops.argsort(x, axis=1)
array([[0, 1],
[1, 0],
[0, 1]], dtype=int32)
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. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.argsort\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/numpy.py#L937-L972) |\n\nReturns the indices that would sort a tensor.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.keras.ops.numpy.argsort`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/argsort)\n\n\u003cbr /\u003e\n\n tf.keras.ops.argsort(\n x, axis=-1\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|-----------------------------------------------------------------------------------------------------|\n| `x` | Input tensor. |\n| `axis` | Axis along which to sort. Defaults to`-1` (the last axis). If `None`, the flattened tensor is used. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Tensor of indices that sort `x` along the specified `axis`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\n#### One dimensional array:\n\n x = keras.ops.array([3, 1, 2])\n keras.ops.argsort(x)\n array([1, 2, 0], dtype=int32)\n\nTwo-dimensional array: \n\n \u003e\u003e\u003e x = keras.ops.array([[0, 3], [3, 2], [4, 5]])\n \u003e\u003e\u003e x\n array([[0, 3],\n [3, 2],\n [4, 5]], dtype=int32)\n \u003e\u003e\u003e keras.ops.argsort(x, axis=0)\n array([[0, 1],\n [1, 0],\n [2, 2]], dtype=int32)\n \u003e\u003e\u003e keras.ops.argsort(x, axis=1)\n array([[0, 1],\n [1, 0],\n [0, 1]], dtype=int32)"]]