groupby_apply#
- pytorch_forecasting.utils._utils.groupby_apply(keys: Tensor, values: Tensor, bins: int = 95, reduction: str = 'mean', return_histogram: bool = False) Tensor | tuple[Tensor, Tensor][source]#
Groupby apply for torch tensors.
- Parameters:
keys (torch.Tensor) – Tensor of groups (
0tobins).values (torch.Tensor) – Values to aggregate - same size as keys.
bins (int, optional) – Total number of groups. Defaults to 95.
reduction (str, optional) – Either “mean” or “sum”. Defaults to “mean”.
return_histogram (bool, optional) – If to return histogram on top. Defaults to False.
- Returns:
Tensor of size
binswith aggregated values and optionally with counts of values.- Return type:
torch.Tensor or tuple of torch.Tensor