代码如下:
#!/usr/bin/python import tensorflow as tf x1 = tf.placeholder(tf.int32,shape=[1],name='x1') x2 = tf.constant(5,name = 'x2') result = x1 + x2 with tf.Session() as sess: print(sess.run(result,{x1:[3]}))
x1 定义为placeholder
x2定义为constant
- 执行结果如下
tf.placeholder( dtype, shape=None, name=None )
dtype: The type of elements in the tensor to be fed.
shape: The shape of the tensor to be fed (optional). If the shape is not specified, you can feed a tensor of any shape.
name: A name for the operation (optional).