import tensorflow as tf
x = tf.placeholder(tf.int32, shape=(None))
y = tf.cumsum(tf.ones_like(x)) - 1
with tf.Session() as sess:
print sess.run(y, {x: [4, 3, 2, 6, 3]})
x = tf.placeholder(tf.float32, shape=(None, 1))
op = tf.range(tf.size(x))[:,tf.newaxis]
# test with different sizes
sess.run(op, {x: np.expand_dims(range(10), axis=-1)})
sess.run(op, {x: np.expand_dims(range(3), axis=-1)})
^{} 做你需要的,你只需要根据你的输入张量的大小来提供大小。因为人们已经告诉你了,我将给你展示另一种方法。你知道吗
^{} 在一个向量上:
你可以试试这个:
相关问题 更多 >
编程相关推荐