Home > OS >  How to permute dimmensions in tensorflow?
How to permute dimmensions in tensorflow?

Time:07-10

I am able to permute the dimmension of the tensor: I'm able to do this in pytorch! But not in tensorflow!

A = torch.rand(1, 2,5)
A = A.permute(0,2,1) 
A.shape

torch.Size([1, 5, 2])

Tensorflow (just a try,I don't know about this):

A = tf.random.normal(1, 2,5)
A = tf.keras.layers.Permute((0, 2, 1))

Not working

CodePudding user response:

Use tf.transpose:

import tensorflow as tf

A = tf.random.normal((1, 2, 5))

A_t = tf.transpose(A, perm=[0, 2, 1])

print(A.shape, A_t.shape)
# (1, 2, 5) (1, 5, 2)
  • Related