# tensorplay.functional.segment_reduce Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.segment_reduce.html ```python tensorplay.functional.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 ``` Perform a segment reduction operation on the input tensor along the specified axis. Parameters: - data ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – The input tensor on which the segment reduction operation will be performed. - reduce ([str](https://docs.python.org/3/builtins/stdtypes.html#str)) – The type of reduction operation. Supported values are sum, mean, max, min, prod. Keyword Arguments: - lengths ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – Length of each segment. Default: None. - offsets ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor), optional) – Offset of each segment. Default: None. - axis ([int](https://docs.python.org/3/builtins/functions.html#int), optional) – The axis perform reduction. Default: 0. - unsafe ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – Skip validation If True. Default: False. - initial (Number, optional) – The initial value for the reduction operation. Default: None. Example: ``` >>> data = tensorplay.tensor([[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]], dtype=tensorplay.float32, device='cuda') >>> lengths = tensorplay.tensor([2, 1], device='cuda') >>> tensorplay.segment_reduce(data, 'max', lengths=lengths) tensor([[ 5., 6., 7., 8.], [ 9., 10., 11., 12.]], device='cuda:0') ```