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

Keras · Class

layers.Permute

Reorders an input tensor's non-batch dimensions using a one-based permutation tuple. The output preserves the same dimensions but presents them in the requested order.

How it works

Permute reorders an input tensor's non-batch dimensions according to the supplied tuple. Dimension positions are one-based, so each tuple value identifies an input dimension and the output retains the same dimensions in the requested order.

Syntax

keras.layers.Permute(dims, **kwargs)

Parameters

NameTypeDescription
dimstuple of integersTuple of integers defining the non-batch dimension order; numbering starts at 1.

Returns

A tensor with the same dimensions as the input, reordered according to dims.

Key points

  • The layer reorders input dimensions according to the pattern supplied at construction.
  • A practical use is adapting dimension order between recurrent and convolutional components.
  • dims is a tuple of integers specifying the permutation.
  • With (1, 3, 2), the first non-batch dimension stays in place while the next two are exchanged.
  • The output has the input shape's dimensions in the requested order.

Common mistakes

  • Do not include the batch dimension in the permutation tuple.
  • Tuple positions use one-based dimension indexing rather than zero-based indexing.

Example: Swap tensor dimensions

import keras

x = keras.Input(shape=(10, 64))
y = keras.layers.Permute((2, 1))(x)
print(y.shape)  # (None, 64, 10)

This swaps the two non-batch dimensions of the input tensor.

When to use it

Adapt tensor layout

A model emits features and timesteps in an order expected by a subsequent layer.

Connect RNNs and convolutional networks

A recurrent block and convolutional block use different dimension conventions.

Interview questions

QWhat does keras.layers.Permute do?

Permute changes only the order of the input dimensions; it does not change their sizes or the batch axis. For an input shaped (batch, 10, 64), Permute((2, 1)) produces (batch, 64, 10).

Follow-up: How would you permute a three-dimensional non-batch shape (a, b, c) to (c, a, b)? Use Permute((3, 1, 2)).

QHow is the dims tuple interpreted?

The dims argument is a tuple of integers describing the output order of the input's non-batch dimensions. Its numbering starts at 1, and the batch dimension is omitted.

Follow-up: What would (1, 3, 2) do to an input with shape (batch, a, b, c)? It would output (batch, a, c, b).

QWhat are the input and output shape rules?

The layer accepts an arbitrary input shape and returns the same shape with dimensions reordered according to dims. For example, an input (None, 10, 64) becomes (None, 64, 10) with (2, 1).

Follow-up: Why might this be useful in a model? It can adapt tensor layouts when connecting recurrent layers and convolutional networks.

  • keras.layers.Reshape
  • keras.layers.Flatten
  • keras.layers.RepeatVector

Source: Permute Layer. Checked 2026-10-15.