tf.repeat() tensorflow


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM