Tensorflow-API : tf.gather

tf.gather

根據索引從參數軸上收集切片,索引必須是任何維度的整數張量 (通常爲 0-D 或 1-D)

import tensorflow as tf

t1 = tf.reshape(tf.range(0,16),[2,2,4])
# [[[ 0  1  2  3]
#   [ 4  5  6  7]]
#
#  [[ 8  9 10 11]
#   [12 13 14 15]]]

# 取第2維中,index爲1,3的數據
t2 = tf.gather(t1,[1,3],axis=2)

with tf.Session() as sess:
    print(sess.run(t1))
    print(sess.run(t2))

[[[ 1  3]
  [ 5  7]]

 [[ 9 11]
  [13 15]]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章