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

Median of a tensor over the given axes, ignoring NaNs.

#### View aliases


**Main aliases**

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

<br />

    tf.keras.ops.nanmedian(
        x, axis=None, keepdims=False
    )

This function computes the median along the specified axis or axes,
skipping any NaN values. If all values along a reduced axis are NaN,
the result is NaN.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor. |
| `axis` | Axis or axes along which the median is computed. If None (default), the median of the flattened tensor is returned. |
| `keepdims` | If True, the reduced axes are retained as dimensions with size one. Defaults to False. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Tensor with the median values, ignoring NaNs. ||

<br />

#### Examples:

    import numpy as np
    from keras import ops
    x = np.array([[1.0, np.nan, 3.0],
                  [np.nan, 2.0, 1.0]])
    ops.nanmedian(x)
    1.5

    ops.nanmedian(x, axis=1)
    array([2., 1.5])

    ops.nanmedian(x, axis=1, keepdims=True)
    array([[2. ],
           [1.5]])