1. 程式人生 > >Tensorflow100天—第2天:基本運算\佔位符

Tensorflow100天—第2天:基本運算\佔位符

# 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'>