tf.repeat(input, repeats, axis=None, name=None)
参数:
举例:
tf.repeat([[1,2],[1,2]], 2, axis=1)
[[1 1 2 2]
[1 1 2 2]]
tf.repeat([[1,2],[1,2]], [1,2], axis=1)
[[1 2 2]
[1 2 2]]
可见对于repeats为一个整数时,所有元素均重复N次,对于一位数组[a,b],input的第一个元素重复a次,第二个元素重复b次。
当axis为0时
tf.repeat([[1,2],[3,4]], [1,2], axis=0)
[[1 2]
[3 4]
[3 4]]
当不设置axis,则将被拉平
tf.repeat([[1,2],[3,4]], 2)
[1 1 2 2 3 3 4 4]
对于一维tensor
tf.repeat([1,2], 2)
[1 1 2 2]
tmp = tf.constant([1, 2])
tf.repeat(tf.reshape(tmp,shape=(2,1)), 2, axis=0)
[[1]
[1]
[2]
[2]]
原文:https://www.cnblogs.com/harbin-ho/p/14684731.html