<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/linalg.py#L445-L472) |

Computes the QR decomposition of a tensor.

#### View aliases


**Main aliases**

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

<br />

    tf.keras.ops.qr(
        x, mode='reduced'
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `x` | Input tensor of shape `(..., M, N)`. |
| `mode` | A string specifying the mode of the QR decomposition. <br /> - 'reduced': Returns the reduced QR decomposition. (default) - 'complete': Returns the complete QR decomposition. |

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tuple containing two tensors. The first tensor of shape `(..., M, K)` is the orthogonal matrix `q` and the second tensor of shape `(..., K, N)` is the upper triangular matrix `r`, where `K = min(M, N)`. ||

<br />

#### Example:

    x = keras.ops.convert_to_tensor([[1., 2.], [3., 4.], [5., 6.]])
    q, r = qr(x)
    print(q)
    array([[-0.16903079  0.897085]
           [-0.5070925   0.2760267 ]
           [-0.8451542  -0.34503305]], shape=(3, 2), dtype=float32)