본문 바로가기

프로그래밍/AI:ML:DL

[TENSORFLOW] 절대값

반응형

import tensorflow as tf


x = tf.placeholder(tf.float32)

y = tf.cond(x<0, lambda : -x, lambda: x)

with tf.Session() as sess:

    for i in [ -1, -2, -77, 0, 1, 99]:

        print(sess.run(y, feed_dict={x:i}))


1.0
2.0
77.0
0.0
1.0
99.0


맞게 하는 건지는 모르겠지만 암튼 이렇게 하면 절대값은 나오더라.

tf.__version__ = 1.0.1

728x90