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:

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]]

Get Neural Network Programming with TensorFlow now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.