# trace

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/trace

```python
Graph.trace(x, *, name=None)
```

Calculate the trace of an object. This can be a an array,
a tensor, or a time-dependent function in the form of a Pwc or an Stf
where values have at least two dimensions.
The trace is calculated on the last two dimensions.

### Parameters
* **x** (*np.ndarray* *or* [*Tensor*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) *or* [*Pwc*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) *or* [*Stf*](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)) – The object whose trace you want to calculate, $\mathop{\mathrm{Tr}}(x)$.
  Must be a matrix or a matrix-valued function.
  For arrays and tensors, the object is converted to a tensor and then
  the operation is applied. For functions of time (Pwcs and Stfs), the composition
  of the operation with the function is computed
  (that is, the operation is applied to the function values).
* **name** (*str* *or* *None* *,* *optional*) – The name of the node. You can only provide a name if the object is not an Stf.
### Returns
The trace of the last two dimension of the given matrix or matrix-valued
function. Outputs will have two fewer dimensions.
### Return type
[Tensor](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Tensor.md#boulderopal.graph.Tensor) or [Pwc](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Pwc.md#boulderopal.graph.Pwc) or [Stf](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Stf.md#boulderopal.graph.Stf)

### SEE ALSO
[`Graph.einsum`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/einsum.md#boulderopal.graph.Graph.einsum)
: Tensor contraction via Einstein summation convention.
