<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/nn.py#L1003-L1051) |

Log-softmax activation function.

#### View aliases


**Main aliases**

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

<br />

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

#### It is defined as:

`f(x) = x - max(x) - log(sum(exp(x - max(x))))`

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor. |
| `axis` | Integer, axis along which the log-softmax is applied. Defaults to `-1`. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor with the same shape as `x`. ||

<br />

#### Example:

    x = np.array([-1., 0., 1.])
    x_log_softmax = keras.ops.log_softmax(x)
    print(x_log_softmax)
    array([-2.40760596, -1.40760596, -0.40760596], shape=(3,), dtype=float64)