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

TensorFlow · Class

layers.Add

tf.keras.layers.Add performs elementwise addition over a list of same-shaped tensors and returns one tensor with that shape. It is commonly used to merge branches in a Keras model.

How it works

Add is a stateless Keras layer that combines a list of tensors by summing corresponding elements. Every input must have the same shape, and the returned tensor keeps that shape; in a functional model, call the layer with the tensors as a list.

Syntax

tf.keras.layers.Add(**kwargs)

Parameters

NameTypeDescription
**kwargskeyword argumentsStandard Keras layer keyword arguments.

Returns

A single tensor containing the elementwise sum, with the same shape as the inputs.

Key points

  • It sums corresponding elements across the supplied tensors.
  • The result is one tensor, and its shape matches the input shape.
  • Create the layer with the Add class, optionally supplying standard layer keyword arguments.
  • In the Functional API, invoke the layer with a list containing the tensors to combine.
  • The class layer has a functional-interface counterpart named keras.layers.add.

Common mistakes

  • Pass a list rather than separate positional tensor arguments, and ensure every tensor has an identical shape.

Example: Elementwise tensor addition

import numpy as np
import tensorflow as tf

x1 = np.array([[1., 2.]])
x2 = np.array([[3., 4.]])
y = tf.keras.layers.Add()([x1, x2])
print(y.numpy())  # [[4. 6.]]

Creates two same-shaped tensors and adds them element by element.

When to use it

Merge a skip connection with a transformed branch

Residual architectures

Combine parallel model branches

Functional Keras graphs

Sum multiple same-shaped tensor values

Tensor arithmetic

Interview questions

QWhat does tf.keras.layers.Add do?

Add performs elementwise addition. It receives a list of tensors with identical shapes and emits one tensor whose shape is unchanged.

Follow-up: How would you merge branches in the Keras Functional API? Instantiate Add and call it with the branch outputs as a list.

QWhat is the Add constructor signature?

The layer constructor accepts **kwargs, which are standard layer keyword arguments. The tensors themselves are supplied when the layer is called.

Follow-up: Why is the tensor list not passed to the constructor? Because the layer object is configured first and then invoked on inputs as part of graph construction.

QWhen would you use Add in a model?

Add is useful for residual or skip connections when the branches produce matching shapes. The output is a single tensor containing the corresponding-element sums.

Follow-up: What must change if branch shapes differ? Project or otherwise transform a branch before Add so the inputs have the same shape.

  • tf.keras.layers.add
  • tf.keras.layers.Layer
  • tf.keras.layers.Dense
  • tf.keras.Model

Source: tf.keras.layers.Add | TensorFlow v2.16.1. Checked 2026-10-15.