# 1. 使用占位符placeholder
import tensorflow as tf
a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16)
add = tf.add(a,b)
mul = tf.multiply(a,b)
with tf.Session() as sess:
print('addition with variables:%i' % sess.run(add, feed_dict={a:1, b:2})) # 这里的1,2替换为numpy,这样计算出来的结果也是numpy
print(type(sess.run(add, feed_dict={a:1, b:2})))
>>>
addition with variables:3
<class 'numpy.int16'>
c = np.ones(1) * 2
d = np.asarray([3])
with tf.Session() as sess:
t = sess.run(add, feed_dict={a:c, b:d})
print(type(t))
>>><class 'numpy.ndarray'>
Tensorflow100天—第2天:基本运算\占位符
猜你喜欢
转载自blog.csdn.net/u011622208/article/details/85238502
今日推荐
周排行