Python – Tensorflow bitwise.bitwise_or() method

Tensorflow bitwise.bitwise_or() method performs the bitwise_or operation and return those bits set, that are either set(1) in a or in b or in both. The operation is done on the representation of a and b.
This method belongs to bitwise module.

Syntax: tf.bitwise.bitwise_or( a, b, name=None)

Arguments

  • a: This must be a Tensor.It should be from the one of the following types: int8, int16, int32, int64, uint8, uint16, uint32, uint64.
  • b: This should also be a Tensor, Type same as a.
  • name: This is optional parameter and this is the name of the operation.

Return: It returns a Tensor having the same type as a and b.

Let’s see this concept with the help of few examples:
Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant a and b 
a = tf.constant(43, dtype = tf.int32) 
b = tf.constant(5, dtype = tf.int32) 
  
# Applying the bitwise_or function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_or(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
    print("Input 2", b)
    print(sess.run(b))
    print("Output: ", c)
    print(sess.run(c))

chevron_right


Output:

Input 1 Tensor("Const_22:0", shape=(), dtype=int32)
43
Input 2 Tensor("Const_23:0", shape=(), dtype=int32)
5
Output:  Tensor("BitwiseOr_1:0", shape=(), dtype=int32)
47

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant vector of size 2 
a = tf.constant([1, 6], dtype = tf.int32) 
b = tf.constant([2, 5], dtype = tf.int32) 
  
# Applying the bitwise_or function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_or(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
    print("Input 2", b)
    print(sess.run(b))
    print("Output: ", c)
    print(sess.run(c))

chevron_right


Output:

Input 1 Tensor("Const_20:0", shape=(2, ), dtype=int32)
[1 6]
Input 2 Tensor("Const_21:0", shape=(2, ), dtype=int32)
[2 5]
Output:  Tensor("BitwiseOr:0", shape=(2, ), dtype=int32)
[3 7]

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.