tf.keras.ops.argsort | TensorFlow v2.16.1 (original) (raw)
Returns the indices that would sort a tensor.
View aliases
Main aliases
tf.keras.ops.argsort(
x, axis=-1
)
| Args | |
|---|---|
| x | Input tensor. |
| axis | Axis along which to sort. Defaults to-1 (the last axis). IfNone, 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)