---
title: Concatenation
description: Concatenate a stream of values.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/aggregation/cat'
---
# Concatenation {#concatenation}

## Module Interface {#module-interface}

### `class torchmetrics.aggregation.CatMetric(nan_strategy='warn', **kwargs)` {#torchmetrics.aggregation.CatMetric}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/aggregation.py#L436-L498)

Concatenate a stream of values.

As input to `forward` and `update` the metric accepts the following input

*   `value` ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)") or [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): a single float or an tensor of float values with arbitrary shape `(...,)`.
    

As output of forward and compute the metric returns the following output

*   `agg` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): scalar float tensor with concatenated values over all input received
    

Parameters:

*   **nan\_strategy** (`Union`\[[`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'error'`, `'warn'`, `'ignore'`, `'disable'`\], [`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]) – options: - `'error'`: if any nan values are encountered will give a RuntimeError - `'warn'`: if any nan values are encountered will give a warning and continue - `'ignore'`: all nan values are silently removed - `'disable'`: disable all nan checks - a float: if a float is provided will impute any nan values with this value
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Raises:

[**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If `nan_strategy` is not one of `error`, `warn`, `ignore`, `disable` or a float

Example

```python
>>> from torch import tensor
>>> from torchmetrics.aggregation import CatMetric
>>> metric = CatMetric()
>>> metric.update(1)
>>> metric.update(tensor([2, 3]))
>>> metric.compute()
tensor([1., 2., 3.])
```

---

**Navigation**

- Parent: [Aggregation](/docs/torchmetrics/1.9.0/aggregation.md)
