Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

layers.Average

keras.layers.Average computes the element-wise mean of a list of same-shaped tensors. It returns one tensor with the same shape, making it useful for merging parallel Keras branches.

How it works

Average receives multiple tensors with matching shapes and computes their element-wise mean, returning one tensor with that same shape. It can be called directly with tensor values or inserted into a functional Keras model to merge parallel branches.

Syntax

keras.layers.Average(**kwargs)

Returns

A single tensor with the same shape as the inputs, containing their element-wise average.

Key points

  • It combines multiple inputs by computing the mean independently at every corresponding position.
  • The output is one tensor whose shape matches the tensors provided to the layer.
  • The constructor accepts standard Keras layer keyword arguments through **kwargs.
  • The layer form is equivalent to Keras's functional average operation for the same input list.
  • It can merge outputs from separate functional-model inputs or other parallel branches.

Common mistakes

  • Every input must be supplied in a list and must have the same shape; mismatched shapes are not supported.

Example: Element-wise averaging

import numpy as np
import keras

x1 = np.array([[1., 2., 3.]])
x2 = np.array([[3., 4., 5.]])
y = keras.layers.Average()([x1, x2])
print(y)

Averages two same-shaped tensors element by element, producing [[2., 3., 4.]].

When to use it

Combine predictions or representations from parallel branches by averaging corresponding values.

Ensemble-style merging

Merge outputs from separate input paths while preserving their tensor shape.

Functional models

Fuse same-shaped features without increasing dimensionality as concatenation would.

Multi-branch architectures

Interview questions

QWhat does the Average layer do?

Average merges a list of tensors by calculating their element-wise mean. The result keeps the same shape as each input.

Follow-up: What must be true before merging? Every tensor in the input list must have matching shape.

QHow is Average invoked?

Instantiate keras.layers.Average() and call it with a list, such as layer([x1, x2]). The list contains the tensors to combine.

Follow-up: How would you use it in a model? Connect parallel branches to the layer and pass its output to later layers.

QWhen would you choose Average instead of concatenation?

The layer is useful for combining parallel model branches when their outputs have identical shapes. It produces one tensor rather than concatenating or increasing the feature dimension.

Follow-up: How does this differ from concatenation? Concatenation joins values along an axis and generally changes that dimension, whereas averaging preserves the branch shape.

  • keras.layers.Add
  • keras.layers.Maximum
  • keras.layers.Minimum
  • keras.layers.average

Source: Average layer - Keras. Checked 2026-10-15.