<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/numpy.py#L1154-L1189) |

Returns the indices that would sort a tensor.

#### View aliases


**Main aliases**

[`tf.keras.ops.numpy.argsort`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/argsort)

<br />

    tf.keras.ops.argsort(
        x, axis=-1
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor. |
| `axis` | Axis along which to sort. Defaults to `-1` (the last axis). If `None`, the flattened tensor is used. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Tensor of indices that sort `x` along the specified `axis`. ||

<br />

#### 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)