• tf.logical_and(a, b):
  • tf.logical_or(a, b):
  • tf.logical_not(a):
  • tf.logical_xor(a, b): 异或

a, b 也可以是列表。

例1:tf.logical_and(a, b) 与

sess = tf.Session()
sess.run(tf.logical_and(True, False))  # False

A = [True, True, False, False]
B = [True, False, True, False]
sess.run(tf.logical_and(A,B))  # array([ True, False, False, False])

例2:tf.logical_or(a, b) 或

sess = tf.Session()
sess.run(tf.logical_or(True, False))  # True

A = [True, True, False, False]
B = [True, False, True, False]
sess.run(tf.logical_or(A,B))  # array([ True,  True,  True, False])

例3:tf.logical_not(a) 非

sess = tf.Session()
sess.run(tf.logical_not(True))  # False
sess.run(tf.logical_not([True, False]))  # array([False,  True])

例4:tf.logical_xor(a, b) 异或

sess = tf.Session()
A = [True, True, False, False]
B = [True, False, True, False]
sess.run(tf.logical_xor(A,B))  # array([False,  True,  True, False])
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐