Python | Método lógico_xor() de Tensorflow

Tensorflow es una biblioteca de aprendizaje automático de código abierto desarrollada por Google. Una de sus aplicaciones es desarrollar redes neuronales profundas.

El módulo tensorflow.mathproporciona soporte para muchas operaciones lógicas básicas. La función tf.logical_xor()[alias tf.math.logical_xor] brinda soporte para la función XOR lógica en Tensorflow. Espera las entradas de tipo bool. Los tipos de entrada son tensores y si los tensores contienen más de un elemento, se calcula un XOR lógico por elementos,  $x XOR y = (x \| \, y) \, \&\& \, ^^21(x \&\& y)$.

Sintaxis : tf.logical_xor(x, y, nombre=Ninguno) o tf.math.logical_xor(x, y, nombre=Ninguno)

Parámetros :
x : un tensor de tipo bool.
y : Un tensor de tipo bool.
nombre (opcional): el nombre de la operación.

Tipo de retorno : un tensor de tipo booleano con el mismo tamaño que el de x o y.

Código:

# Importing the Tensorflow library
import tensorflow as tf
  
# A constant vector of size 4
a = tf.constant([True, False, True, False], dtype = tf.bool)
b = tf.constant([True, False, False, True], dtype = tf.bool)
  
# Applying the XOR function and
# storing the result in 'c'
c = tf.logical_xor(a, b, name ='logical_xor')
  
# Initiating a Tensorflow session
with tf.Session() as sess:
    print('Input type:', a)
    print('Input a:', sess.run(a))
    print('Input b:', sess.run(b))
    print('Return type:', c)
    print('Output:', sess.run(c))

Producción:

Input type: Tensor("Const:0", shape=(4, ), dtype=bool)
Input a: [ True False  True False]
Input b: [ True False False  True]
Return type: Tensor("logical_xor:0", shape=(4, ), dtype=bool)
Output: [False False  True  True]

Publicación traducida automáticamente

Artículo escrito por sanskar27jain y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *