import tensorflow as tf
x = tf.Variable(3, name='x')
y = x * 5
print(y)

这个时候输出的是: Tensor("mul:0", shape=(), dtype=int32) ,并不是预料中的15,那么怎么输出15呢?如下:

import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
x = tf.Variable(3, name='x')
y = x * 5
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())

# Add print operation
#x = tf.Print(x, [x], message="This is x: ")

# Add more elements of the graph using a
#b = tf.add(x,x).eval()
print(x.eval())
print(y.eval())

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-02-11
  • 2022-12-23
  • 2022-01-20
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-04-05
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案