给定一批输入大小(None,1),是否可以创建形状相同的有序整数张量?

例如:

input = [3, 2, 3, 7], output = [0, 1, 2, 3]


例如:

input = [9, 3, 12, 4, 34 .....], output = [0, 1, 2, 3, ....]

最佳答案

tf.range()做您需要的事情,您只需要根据输入张量的大小来提供大小即可。因为人们已经告诉过您这一点,所以我将向您展示另一种方法。

tf.cumsum()在那个向量上:

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]})

关于python - 创建形状的有序整数张量(无,1),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44850342/

10-12 12:43
查看更多