In [1]:
import tensorflow as tf
import numpy as np
In [5]:
input = [
[[11, 12, 13], [14, 15, 16]],
[[21, 22, 23], [24, 25, 26]],
[[31, 32, 33], [34, 35, 36]],
[[41, 42, 43], [44, 45, 46]],
[[51, 52, 53], [54, 55, 56]],
]
print(np.asarray(input).shape)
s1 = tf.slice(input, [1, 0, 0], [1, 1, 3])
s2 = tf.slice(input, [2, 0, 0], [3, 1, 2])
s3 = tf.slice(input, [0, 0, 1], [4, 1, 1])
s4 = tf.slice(input, [0, 0, 1], [1, 0, 1])
s5 = tf.slice(input, [2, 0, 2], [-1, -1, -1]) # negative value means the function cutting tersors automatically
tf.global_variables_initializer()
with tf.Session() as s:
print (s.run(s1))
print (s.run(s2))
print (s.run(s3))
print (s.run(s4))
In [10]:
input = [[1, 2, 3, 4, 5 ],
[11, 22, 33, 44, 55],
[111, 222, 333, 444, 555]]
print(np.asarray(input).shape)
print(input)
s1 = tf.slice(input, [0, 0], [-1,2])
tf.global_variables_initializer()
with tf.Session() as s:
print (s.run(s1))