tf.keras.backend.permute_dimensions

TensorFlow 2 version View source on GitHub

Permutes axes in a tensor.

x Tensor or variable.
pattern A tuple of dimension indices, e.g. (0, 2, 1).

A tensor.

Example:

a = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])
a
<tf.Tensor: id=49, shape=(4, 3), dtype=int32, numpy=
array([[ 1,  2,  3],
       [ 4,  5,  6],
       [ 7,  8,  9],
       [10, 11, 12]], dtype=int32)>
tf.keras.backend.permute_dimensions(a, pattern=(1, 0))
<tf.Tensor: id=52, shape=(3, 4), dtype=int32, numpy=
array([[ 1,  4,  7, 10],
       [ 2,  5,  8, 11],
       [ 3,  6,  9, 12]], dtype=int32)>