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

TensorFlow · Function

tf.split

Splits a tensor along a chosen dimension and returns the pieces as a list. Use an integer for equal-sized outputs or provide explicit sizes for uneven outputs.

How it works

tf.split divides a tensor along one selected dimension and returns the resulting tensors as a list. You can request an equal number of pieces or provide the exact size of each piece; the latter changes only the selected dimension while preserving the others.

Syntax

tf.split(value, num_or_size_splits, axis=0, num=None, name='split')

Parameters

NameTypeDescription
valueTensorThe Tensor to split.
num_or_size_splitsint, 1-D integer Tensor, or Python listAn integer number of equal splits, or a one-dimensional integer Tensor or Python list containing each output size.
axisint or scalar int32 TensorDimension along which to split; defaults to 0 and must be in the valid rank range.
numint or NoneOptional output count when it cannot be inferred from the size specification.
namestr or NoneOptional operation name.

Returns

A list of tensors split from value along axis.

Key points

  • The operation produces a Python list containing the tensor pieces.
  • An integer argument means “make this many partitions” along the selected dimension.
  • Equal-sized partitions require exact divisibility of the chosen input dimension.
  • A one-dimensional size specification determines the number of returned tensors.
  • Each output retains every input dimension unchanged except the split dimension.
  • The split dimension can be supplied as a regular integer or scalar int32 tensor.

Common mistakes

  • When specifying a number of equal splits, the selected dimension must be evenly divisible by that number.
  • When passing explicit sizes, their total must equal the input size along the chosen axis.
  • axis must identify a valid dimension, including supported negative indices.

Example: Split a tensor along an axis

import tensorflow as tf

x = tf.reshape(tf.range(12), [2, 6])
parts = tf.split(x, num_or_size_splits=3, axis=1)

for part in parts:
    print(part.numpy())

This creates a 2×6 tensor and returns three tensors by dividing its second dimension into equal sections.

When to use it

Equal partitioning

Divide a feature or sequence dimension into equal sections for parallel processing.

Uneven partitioning

Extract variable-width slices when output sections have different sizes.

Branching tensor pipelines

Separate a batch, channel, or spatial dimension before applying independent tensor operations.

Interview questions

QWhat does tf.split do when given an integer split count?

tf.split returns a list of tensors created by partitioning value along axis. With an integer num_or_size_splits, it makes that many equal-sized outputs, so the selected dimension must divide evenly.

Follow-up: What changes when num_or_size_splits is a list? Each list entry specifies one output's size along axis, and the entries must sum to the input size there.

QHow does the axis argument affect tf.split?

The axis argument selects the dimension to partition and defaults to 0. It may be an integer or scalar int32 tensor, and it must fall within the valid rank-based range.

Follow-up: Why can a negative axis be useful? It addresses dimensions from the end, making code less dependent on the tensor's leading-dimension layout.

QHow does tf.split support uneven partitions?

num_or_size_splits can be a one-dimensional integer tensor or Python list of output sizes. The i-th output keeps value's shape except that its axis dimension becomes the i-th requested size.

Follow-up: When might num be needed? It can specify the output count when TensorFlow cannot infer it from the shape of size_splits.

  • tf.concat
  • tf.raw_ops.Split
  • tf.sparse.split
  • tf.unstack

Source: Split. Checked 2026-10-15.