[PYTHON] Tensorflow API: tf.reverse

https://www.tensorflow.org/api_docs/python/tf/reverse

reverse(
    tensor,
    axis,
    name=None
)

Example of use

import tensorflow as tf

# Define a 3D tensor
x = tf.constant([[[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                [[11, 12, 13], [14, 15, 16], [17, 18, 19]]])

sess = tf.Session()
x_reverse_0 = tf.reverse(x, [0])
x_reverse_1 = tf.reverse(x, [1])
x_reverse_2 = tf.reverse(x, [2])
x_reverse_0_1 = tf.reverse(x, [0, 1])
x_reverse_0_1_2 = tf.reverse(x, [0, 1, 2])

# Check the result
print(str(sess.run(x)) + '\n')

print("tf.reverse(x, [0]):")
print(str(sess.run(x_reverse_0)) + '\n')

print("tf.reverse(x, [1]):")
print(str(sess.run(x_reverse_1)) + '\n')

print("tf.reverse(x, [2]):")
print(str(sess.run(x_reverse_2)) + '\n')

print("tf.reverse(x, [0, 1]):")
print(str(sess.run(x_reverse_0_1)) + '\n')

print("tf.reverse(x, [0, 1, 2]):")
print(str(sess.run(x_reverse_0_1_2)) + '\n')
[[[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]]

[[11 12 13]
 [14 15 16]
 [17 18 19]]]

tf.reverse(x, [0]):
[[[11 12 13]
 [14 15 16]
 [17 18 19]]

[[ 1  2  3]
 [ 4  5  6]
 [ 7  8  9]]]

tf.reverse(x, [1]):
[[[ 7  8  9]
 [ 4  5  6]
 [ 1  2  3]]

[[17 18 19]
 [14 15 16]
 [11 12 13]]]

tf.reverse(x, [2]):
[[[ 3  2  1]
 [ 6  5  4]
 [ 9  8  7]]

[[13 12 11]
 [16 15 14]
 [19 18 17]]]

tf.reverse(x, [0, 1]):
[[[17 18 19]
 [14 15 16]
 [11 12 13]]

[[ 7  8  9]
 [ 4  5  6]
 [ 1  2  3]]]

tf.reverse(x, [0, 1, 2]):
[[[19 18 17]
 [16 15 14]
 [13 12 11]]

[[ 9  8  7]
 [ 6  5  4]
 [ 3  2  1]]]

Recommended Posts

Tensorflow API: tf.reverse
Tensorflow API: tf.truncated_normal
Tensorflow API: FLAGS
TensorFlow API memo
[TF] About Tensorflow API
TensorFlow API memo (Python)
Logo detection using TensorFlow Object Detection API
Tensorflow Glossary
tensorflow mnist_deep.py
TensorFlow tutorial tutorial
Find polynomial approximations using TensorFlow 2.x Low-level API