Stephane Bersier
Stephane Bersier

Reputation: 779

Applying a permutation along one axis in TensorFlow

How to permute "dimensions" along a single axis of a tensor?

Something akin to tf.transpose, but at the level of "dimensions" along an axis, instead of at the level of axes.

To permute them randomly (along the first axis), there it tf.random.shuffle, and to shift them, there is tf.roll. But I can't find a more general function that would apply any given permutation.

Upvotes: 1

Views: 484

Answers (1)

Stephane Bersier
Stephane Bersier

Reputation: 779

tf.gather can be used to that end. In fact, it is even more general, as the indices it takes as one of its inputs don't need to represent a permutation.

Upvotes: 3

Related Questions