Friday, September 26, 2025
HomeLanguagesPython | Tensorflow logical_or() method

Python | Tensorflow logical_or() 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 mathematical operations. Function tf.logical_or() [alias tf.math.logical_or] provides support for the logical OR 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 OR is computed,  $x OR y$ .

Syntax: tf.logical_or(x, y, name=None) or tf.math.logical_or(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 OR function and
# storing the result in 'c'
c = tf.logical_or(a, b, name ='logical_or')
  
# 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 True True]

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32321 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6687 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6801 POSTS0 COMMENTS
Ted Musemwa
7072 POSTS0 COMMENTS
Thapelo Manthata
6761 POSTS0 COMMENTS
Umr Jansen
6766 POSTS0 COMMENTS