Tensorflow Practice 2-2

Posted stevensun1991

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Tensorflow Practice 2-2相关的知识,希望对你有一定的参考价值。

 1 import tensorflow as tf
 2 import os
 3 os.environ[TF_CPP_MIN_LOG_LEVEL] = 2
 4 
 5 x = tf.Variable([1, 2])
 6 a = tf.constant([3, 3])
 7 ‘‘‘增加一个减法op‘‘‘
 8 sub = tf.subtract(x, a)
 9 ‘‘‘增加一个加法op‘‘‘
10 add = tf.add(x, sub)
11 
12 init = tf.global_variables_initializer()
13 
14 with tf.Session() as sess:
15     sess.run(init)
16     print(sess.run(sub))
17     print(sess.run(add))
18 
19 ‘‘‘创建一个变量初始化为0‘‘‘
20 state = tf.Variable(0, name=counter)
21 ‘‘‘创建一个op,作用是使state加1‘‘‘
22 new_value = tf.add(state, 1)
23 ‘‘‘赋值op‘‘‘
24 update = tf.assign(state, new_value)
25 init = tf.global_variables_initializer()
26 with tf.Session() as sess:
27     sess.run(init)
28     print(sess.run(state))
29     for _ in range(5):
30         print(sess.run(update))

 

以上是关于Tensorflow Practice 2-2的主要内容,如果未能解决你的问题,请参考以下文章

Tensorflow Practice 2-1

Tensorflow Practice 2-3

Tensorflow Practice 2-4

tensorflow学习-------激活函数(activation function)

TensorFlow 2 / 2.0 入门教程实战案例

[我只是简单地输入了tf.Tensor Tensorflow 2.2.0中给出的代码,这是我的代码:请为错误提供解决方案