Python | Tensorflow logical_and() method
Tensorflow is an open-source machine learning library developed by Google. One of its applications is to develop deep neural networks.
The module tensorflow.math provides support for many basic logical operations. Function tf.logical_and() [alias tf.math.logical_and] provides support for the logical AND function in Tensorflow. It expects the input of bool type. The input types are tensor and if the tensors contains more than one element, an element-wise logical AND is computed,
.
Syntax: tf.logical_and(x, y, name=None) or tf.math.logical_and(x, y, name=None)
Parameters:
x: A Tensor of type bool.
y: A Tensor of type bool.
name (optional): The name for the operation.Return type: A Tensor of bool type with the same size as that of x or y.
Code:
# 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 AND function and # storing the result in 'c' c = tf.logical_and(a, b, name ='logical_and') # 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)) |
Output:
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_and:0", shape=(4, ), dtype=bool)
Output: [ True False False False]
Recommended Posts:
- Python | Tensorflow cos() method
- Python | Tensorflow tan() method
- Python | Tensorflow exp() method
- Python | Tensorflow abs() method
- Python | Tensorflow sin() method
- Python | Tensorflow log() method
- Python | Tensorflow asinh() method
- Python | Tensorflow acosh() method
- Python | Tensorflow atan() method
- Python | Tensorflow cosh() method
- Python | Tensorflow sinh() method
- Python | Tensorflow asin() method
- Python | Tensorflow acos() method
- Python | Tensorflow atanh() method
- Python | Tensorflow logical_xor() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


