a = tf.constant(1)
b = tf.constant(2)
c = tf.add(a, b)
sess = tf.Session()
sess.run(c)
print(c)
결과
Tensor("Add:0", shape=(), dtype=int32)
import tensorflow as tf
a = tf.Variable(5)
b = tf.Variable(3)
c = tf.multiply(a, b)
init= tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
sess.run(c)
a = tf.Variable(15)
c = tf.multiply(a, b)
init = tf.global_variables_initializer()
sess.run(init)
sess.run(c)
tf.placeholder(dtype, shape, name)
import tensorflow as tf
mathScore = [85, 99, 84, 97, 92]
englishScore = [59, 80, 84, 68, 77]
a = tf.placeholder(dtype=tf.float32)
b = tf.placeholder(dtype=tf.float32)
y = (a+b)/2
sess = tf.Session()
sess.run(y, feed_dict={a:mathScore, b:englishScore})
결과
array([72. , 89.5, 84. , 82.5, 84.5], dtype=float32)
import tensorflow as tf
a = tf.constant(3)
b = tf.constant(5)
sess = tf.Session()
# 덧셈
c = tf.add(a,b)
sess.run(c)
# 뺄셈
c = tf.subtract(a,b)
sess.run(c)
# 곱셈
c = tf.multiply(a, b)
sess.run(c)
# 나눗셈 몫
c = tf.truediv(a, b)
sess.run(c)
# 나머지
c = tf.mod(b, a)
sess.run(c)
# 절대값
c = tf.abs(-a)
sess.run(c)
a = tf.constant(17.5)
b = tf.constant(5.0)
# 음수 반환
c = tf.negative(a)
sess.run(c)
# 부호 반환
c = tf.sign(a)
sess.run(-c)
# 제곱 함수
c = tf.square(a)
sess.run(c)
# 거듭 제곱, 너무 큰 값은 못구한다고 뜸
c = tf.pow(b, 2)
sess.run(c)
# 더 큰 값 확인
c = tf.maximum(a, b)
sess.run(c)
# 더 작은 값
c = tf.minimum(a, b)
sess.run(c)
# 지수 값
c = tf.exp(b)
sess.run(c)