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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.