首页 > 其他 > 详细

tf.repeat() tensorflow

时间:2021-04-21 16:34:45      阅读:26      评论:0      收藏:0      [点我收藏+]

tf.repeat(input, repeats, axis=None, name=None)

参数:

  • input: tensor
  • repeats: 重复次数, note: len(repeats) must equal input.shape[axis] if axis is not None
  • axis:维度,1则横向增加,0则列向增加。如果axis没有参数,则会先flatten数组,变成一维再重复

举例:

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

tf.repeat() tensorflow

原文:https://www.cnblogs.com/harbin-ho/p/14684731.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!