![Neural Network Programming with TensorFlow](https://wfqqreader-1252317822.image.myqcloud.com/cover/537/36700537/b_36700537.jpg)
上QQ阅读APP看书,第一时间看更新
Matrix transpose
Transposition of the matrix is the mirror image of the matrix across the main diagonal. A symmetric matrix is any matrix that is equal to its own transpose:
![](https://epubservercos.yuewen.com/CB0D7A/19470401501607606/epubprivate/OEBPS/Images/8ab26f97-c7f1-4046-9494-9aba9b6d4ac7.jpg?sign=1739273839-GSfMti1Hr4lkhAdNxwZRpEUPKMGt2p2S-0-4920a50faf46df2aeccfe2e9ac6803d3)
The following example shows how to use a transpose operator on tensor objects:
import tensorflow as tf
x = [[1,2,3],[4,5,6]]
x = tf.convert_to_tensor(x)
xtrans = tf.transpose(x)
y=([[[1,2,3],[6,5,4]],[[4,5,6],[3,6,3]]])
y = tf.convert_to_tensor(y)
ytrans = tf.transpose(y, perm=[0, 2, 1])
with tf.Session() as sess:
print(sess.run(xtrans))
print(sess.run(ytrans))
The output of the listing is shown as follows:
[[1 4] [2 5] [3 6]]