获取tensorflow中tensor的值


tensorflow中的tensor值的获取:

import tensorflow as tf

#定义变量a
a=tf.Variable([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]])

#定义索引
indics=[[0,0,0],[0,1,1],[0,1,2]]

#把a中索引为indics的值取出
b=tf.gather_nd(a,indics)

#初始化
init=tf.global_variables_initializer()
with tf.Session() as sess:
    #执行初始化
    sess.run(init)

    #打印结果
    print(a.eval())
    print(b.eval())

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM