Tensorflow细节-P42张量的概念及使用

1、运行以下代码

import tensorflow as tf
a = tf.constant([1.0, 2.0], name="a")
b = tf.constant([2.0, 3.0], name="b")
result = a + b
print result

sess = tf.InteractiveSession ()
print(result.eval())
sess.close()

得到
image.png
其中,add与代码中的add有关,0表示第一个输出,图中的shape(2, )则表示一个长度为2的一维数组

2、讲一个特别重要的概念——result.get_shape()可以获得张量的维度信息

3、见到result.eval(session=sess)不要奇怪,sess = tf.Interactivesession()也不要奇怪,其他的就算了

4、至于

g=tf.Graph()
with g.device('/gpu:0'):
  result = a+b

这种概念就不讲了

猜你喜欢

转载自www.cnblogs.com/liuboblog/p/11615641.html