> For the complete documentation index, see [llms.txt](https://ncxlib.gitbook.io/ncxlib/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ncxlib.gitbook.io/ncxlib/getting-started/api-documentation/overview/activation/softmax.md).

# Softmax

```python
class Softmax(Activation):
    def apply(self, x: np.ndarray) -> np.ndarray:
        """
        Applies the Softmax function to the input array.

        Args:
          x (np.ndarray): Input array.

        Returns:
          np.ndarray: Softmax output.
        """
        e_x = np.exp(x - np.max(x, axis=-1, keepdims=True))
        self.activated = e_x / np.sum(e_x, axis=-1, keepdims=True)
        return self.activated

    def derivative(self, x: np.ndarray) -> np.ndarray:
        """
        Calculates the derivative of the Softmax function.

        Args:
          x (np.ndarray): Input array (not used directly, 
                          but kept for consistency with other activations).

        Returns:
          np.ndarray: Derivative of Softmax (Jacobian matrix).
        """
        s = self.activated.reshape(-1, 1)
        return np.diagflat(s) - np.dot(s, s.T)
```
