tf.gather:用一个一维的索引数组,将张量中对应索引的向量提取出来

import tensorflow as tf
 
a = tf.Variable([[1,2,3,4,5], [6,7,8,9,10], [11,12,13,14,15]])
index_a = tf.Variable([0,2])
 
b = tf.Variable([1,2,3,4,5,6,7,8,9,10])
index_b = tf.Variable([2,4,6,8])
 
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print(sess.run(tf.gather(a, index_a)))
    print(sess.run(tf.gather(b, index_b)))
 
#  [[ 1  2  3  4  5]
#   [11 12 13 14 15]]
 
#  [3 5 7 9]

 

相关文章:

  • 2021-04-12
  • 2021-07-17
  • 2021-08-18
  • 2021-11-14
  • 2021-08-03
  • 2022-03-09
  • 2022-02-21
  • 2021-10-27
猜你喜欢
  • 2021-04-12
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2021-08-11
  • 2021-06-08
相关资源
相似解决方案