<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/numpy_ops/np_array_ops.py#L305-L344) |

TensorFlow variant of NumPy's `diag`.

    tf.experimental.numpy.diag(
        v, k=0
    )

Raises an error if input is not 1- or 2-d.

See the NumPy documentation for [`numpy.diag`](https://numpy.org/doc/stable/reference/generated/numpy.diag.html).