In [11]:
import tensorflow as tf
import numpy as np
import gzip
import pickle

In [7]:
ph = tf.placeholder(shape=[None,3], dtype=tf.int32)

# look the -1 in the first position
x = tf.slice(ph, [0, 0], [-1, 2])

input_ = np.array([[1,2,3],
                   [3,4,5],
                   [5,6,7]])

with tf.Session() as sess:
        sess.run(tf.initialize_all_variables())
        print(sess.run(x, feed_dict={ph: input_}))


WARNING:tensorflow:From <ipython-input-7-2b5e467ae06d>:11: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
[[1 2]
 [3 4]
 [5 6]]

In [29]:
input_ = np.array([[1,2,0,0,0,0,0,0,0,0],[3,4,0,0,0,0,0,0,0,0]])

In [30]:
input_


Out[30]:
array([[1, 2, 0, 0, 0, 0, 0, 0, 0, 0],
       [3, 4, 0, 0, 0, 0, 0, 0, 0, 0]])

In [31]:
input_.shape


Out[31]:
(2, 10)

In [32]:
ph = tf.placeholder(shape=[None,10],dtype=tf.int32)

In [33]:
x = tf.slice(ph,[0,0],[-1,2])

In [34]:
x


Out[34]:
<tf.Tensor 'Slice_10:0' shape=(?, 2) dtype=int32>

In [35]:
with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        print(sess.run(x, feed_dict={ph: input_}))


[[1 2]
 [3 4]]

In [ ]: