---
title: thunder.clang.matrix_transpose
description: Transposes the last two dimensions of a tensor.
canonical: >-
  https://lightning.ai/docs/thunder/stable/api-reference/generated/thunder.clang.matrix_transpose
---
# thunder.clang.matrix_transpose {#thunder-clang-matrix-transpose}

### `thunder.clang.matrix_transpose(a)` {#thunder.clang.matrix_transpose}

[\[source\]](https://github.com/Lightning-AI/lightning-thunder/blob/0.2.6/thunder/core/langctxs.py#L1080-L1112)

Transposes the last two dimensions of a tensor.

This function is used to implement the .mT attribute.

Parameters:

*   **a** ([_TensorProxy_](/docs/thunder/core/generated/thunder.core.proxies.TensorProxy#thunder.core.proxies.TensorProxy "thunder.core.proxies.TensorProxy")) – The tensor to transpose.
    
*   **a** ([_TensorProxy_](/docs/thunder/core/generated/thunder.core.proxies.TensorProxy#thunder.core.proxies.TensorProxy "thunder.core.proxies.TensorProxy")) –
    

Returns:

The transposed tensor.

Return type:

[TensorProxy](/docs/thunder/core/generated/thunder.core.proxies.TensorProxy#thunder.core.proxies.TensorProxy "thunder.core.proxies.TensorProxy")

Examples

```python
>>> a = torch.tensor([[1, 2, 3], [4, 5, 6]])
>>> def func(x): return x.mT
>>> traced_func = thunder.make_traced(func, executor="torch")
>>> traced_func(a)
tensor([[1, 4],
        [2, 5],
        [3, 6]])
```

---

**Navigation**

- Parent: [Generated](/docs/thunder/0.2.6/api-reference/generated.md)
