티스토리 뷰

Tensorflow에서 제공하는 tf.math.equal 함수는 입력값 두개가 같은지 다른지 비교해주는 함수이다.

 

기본 형태로

tf.math.equal(x, y, name=None)

형태를 취한다.

 x와 y의 값을 원소별로 같은지 다른지 비교해주고 각각에 대한 True or False를 return해주는 함수이다.

 

 

예제 1)

x = tf.constant([2, 4])
y = tf.constant([2, 4])
tf.math.equal(x, y)

에 대해서는 값이 [True, True]로 나온다.

 

예제 2)

x = tf.constant([2,4])
y = tf.constant(2)
tf.math.equal(x, y)

에 대해서는 값이 [True, False]로 나온다.

 

예제 3)

x = tf.constant([2, 2])
y = tf.constant(2)
tf.math.equal(x, y)

에 대해서는 값이 [True, True] 로 나온다.

비교하는 값이 하나밖에 없을 때는 첫번째 값과 계속 비교한다,

그러나 2개와 3개를 비교하려고 하면 incompatible shape error가 발생한다(예제 4).

 

예제 4)

x = tf.constant([2, 3, 2])
y = tf.constant([3, 2])
tf.math.equal(x, y)

(error massage)

tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [3] vs. [2] [Op:Equal]

 

 

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함