2.1 TensorBoard
a = tf.constant(2)
b = tf.constant(3)
x = tf.add(a, b)
writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
writer.close()
2.2 Constants
tf.constant(
value,
dtype=None,
shape=None,
name='Const',
verify_shape=False
)
import tensorflow as tf
a = tf.constant([2, 2], name='a')
b = tf.constant([[0, 1], [2, 3]], name='b')
2.2.1 Broadcasting
import tensorflow as tf
#a是一个1x2矩阵,b是一个2x2矩阵
a = tf.constant([2, 2], name='a')
b = tf.constant([[0, 1], [2, 3]], name='b')
#a,b的shape不同,发生broadcasting,a==>2x2
#转化的方法为复制a的最后一个元素,所以a被broadcast成[[2,2],[2,2]]
x = tf.multiply(a, b, name='mul')
with tf.Session() as sess:
print(sess.run(x))
# >> [[0 2]
# [4 6]]
2.2.2 有特定值的constants
tf.zeros(shape, dtype=tf.float32, name=None)
tf.zeros_like(input_tensor, dtype=None, name=None, optimize=True)
tf.ones(shape, dtype=tf.float32, name=None)
tf.ones_like(input_tensor, dtype=None, name=None, optimize=True)
tf.fill(dims, value, name=None)
# creates a tensor filled with a scalar value.
tf.fill([2, 3], 8) ==> [[8, 8, 8], [8, 8, 8]]
线性插值,start,stop,num(插值个数)
tf.lin_space(start, stop, num, name=None)
# tf.lin_space(10.0, 13.0, 4) ==> [10. 11. 12. 13.]
#start(包括start),limit(最后结果小于limit),delta步长
tf.range(start, limit=None, delta=1, dtype=None, name='range')
# tf.range(3, 18, 3) ==> [3 6 9 12 15]
# 从0开始,5个数
# tf.range(5) ==> [0 1 2 3 4]
node.eval()也可以运行session,得到输出结果. 需要运行 tf.InteractiveSession()
TensorFlow Data Types
Variables
lecture
Importing Data
lecture