#coding:utf-8
"""
学习tensorflow基本语法
"""
import tensorflow as tf
"""
a = tf.constant([[3,3]]) #tf.constant定义常量
b = tf.constant([[2],[2]])
c = tf.matmul(a,b) #matmul函数
with tf.Session() as sess:
result = sess.run([c]) #需要进行run
print result
"""
"""
state = tf.Variable(0,name='counter')#定义变量
one = tf.constant(1)
new_value = tf.add(state,one)
update = tf.assign(state,new_value) #tf.assign将new_value的值赋值给state
init_op = tf.initialize_all_variables() #初始化所有变量
with tf.Session() as sess:
sess.run(init_op) #run变量
for i in range(20):
sess.run(update) #run
print sess.run(state) #run
"""
"""
a = tf.constant(3)
b = tf.constant(2)
c = tf.constant(5)
num1 = tf.add(a,b)
num2 = tf.mul(c,num1)
with tf.Session() as sess:
result = sess.run([num1,num2]) #run
print result
"""
"""
input1 = tf.placeholder(tf.float32) #placeholder占位
input2 = tf.placeholder(tf.float32)
output = tf.mul(input1,input2)
with tf.Session() as sess:
print sess.run([output],feed_dict={input1:[7],input2:[2]}) #feed_dict以字典的方式赋值
"""
tensorflow基本语法
最新推荐文章于 2020-09-07 14:04:00 发布