Skip to content

Instantly share code, notes, and snippets.

@shubhamwagh
Created December 6, 2023 16:53
Show Gist options
  • Save shubhamwagh/c26811ce7be45564c382f3e4f9df6436 to your computer and use it in GitHub Desktop.
Save shubhamwagh/c26811ce7be45564c382f3e4f9df6436 to your computer and use it in GitHub Desktop.
tf tranpose alternative
shape = (3,4,5)
a = tf.random.uniform(shape)
a_t = tf.transpose(a,(1,0,2)) # permuting first and second axis
a_concat = tf.concat([tf.reshape(a[i:i+1,:,:],(shape[1],1,shape[2])) for i in range(shape[0])],axis=1)
tf.debugging.assert_equal(a_t,a_concat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment