If I already know all the shapes of the array, what is the difference between reshape and transpose?

When I learned from other people’s models, I found that sometimes they would call transpose again after reshape to adjust the shape of the array. But if I already know the shape, wouldn’t it be OK to change the shape when I was directly in reshape? Why do I have to do another transpose

code was :
x[i] = tf.transpose(tf.reshape(x[i],(bs,self.na, self.no, ny, nx)),perm=[0,1,3,4,2])

as far as I understand

reshape will keep the values in the same order
transpose changes them

so they have different uses

some more details here: tf.reshape  |  TensorFlow v2.9.1

Here’s an example illustrating lgusm’s explanation.

x = [ [1, 2, 3],
      [4, 5, 6] ]

# Rows are now columns.
tf.transpose(x) == [ [1, 4],
                     [2, 5],
                     [3, 6] ]

# Values remain in the same order.
tf.reshape(x, [3, 2]) == [ [1, 2],
                           [3, 4],
                           [5, 6] ]
1 Like

thank for your report