# tf.data.experimental.Reducer

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/data/experimental/ops/grouping.py#L388-L428) |

A reducer is used for reducing a set of elements.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.data.experimental.Reducer`](https://www.tensorflow.org/api_docs/python/tf/data/experimental/Reducer)

<br />

    tf.data.experimental.Reducer(
        init_func, reduce_func, finalize_func
    )

A reducer is represented as a tuple of the three functions:

- init_func - to define initial value: key =\> initial state
- reducer_func - operation to perform on values with same key: (old state, input) =\> new state
- finalize_func - value to return in the end: state =\> result

For example,

    def init_func(_):
      return (0.0, 0.0)

    def reduce_func(state, value):
      return (state[0] + value['features'], state[1] + 1)

    def finalize_func(s, n):
      return s / n

    reducer = tf.data.experimental.Reducer(init_func, reduce_func, finalize_func)

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `finalize_func` | <br /> <br /> |
| `init_func` | <br /> <br /> |
| `reduce_func` | <br /> <br /> |

<br />