torch.segment_reduce#
- torch.segment_reduce(data: Tensor, reduce: str, *, lengths: Tensor | None = None, indices: Tensor | None = None, offsets: Tensor | None = None, axis: _int = 0, unsafe: _bool = False, initial: Number | _complex | None = None) Tensor#
在指定轴上对输入张量执行分段归约操作。
- 参数
- 关键字参数
示例
>>> data = torch.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=torch.float32, device='cuda') >>> lengths = torch.tensor([2, 1], device='cuda') >>> torch.segment_reduce(data, 'max', lengths=lengths) tensor([[ 5., 6., 7., 8.], [ 9., 10., 11., 12.]], device='cuda:0')