码迷,mamicode.com
首页 > 其他好文 > 详细

[tensorflow] tf.gather使用方法

时间:2020-10-13 17:50:02      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:索引数组   ini   class   glob   style   dex   flow   imp   方法   

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]

 

[tensorflow] tf.gather使用方法

标签:索引数组   ini   class   glob   style   dex   flow   imp   方法   

原文地址:https://www.cnblogs.com/yibeimingyue/p/13808083.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!