4

Python - Tensorflow bitwise.invert() method - GeeksforGeeks

 1 year ago
source link: https://www.geeksforgeeks.org/python-tensorflow-bitwise-invert-method/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python – Tensorflow bitwise.invert() method

  • Last Updated : 04 Jun, 2020

Tensorflow bitwise.invert() method performs the invert operation and the result will invert the bits, Like 0 to 1 and 1 to 0. The operation is done on the representation of a.
This method belongs to bitwise module.

Syntax: tf.bitwise.invert( a, 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.
  • name: This is optional parameter and this is the name of the operation.

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

Let’s see this concept with the help of few examples:
Example 1:
import tensorflow as tf 
# A constant a 
a = tf.constant(6, dtype = tf.int32)  
# Applying the invert function 
# storing the result in 'c' 
c = tf.bitwise.invert(a) 
# Initiating a Tensorflow session 
with tf.Session() as sess:
print("Input 1", a)
print(sess.run(a))
print("Output: ", c)
print(sess.run(c))

Output:

Input 1 Tensor("Const_40:0", shape=(), dtype=int32)
6
Output:  Tensor("Invert_4:0", shape=(), dtype=int32)
-7

Example 2:

import tensorflow as tf 
# A constant a 
a = tf.constant([1, 4, 7], dtype = tf.int32)  
# Applying the invert function 
# storing the result in 'c' 
c = tf.bitwise.invert(a) 
# Initiating a Tensorflow session 
with tf.Session() as sess:
print("Input 1", a)
print(sess.run(a))
print("Output: ", c)
print(sess.run(c))

Output:

Input 1 Tensor("Const_39:0", shape=(3, ), dtype=int32)
[1 4 7]
Output:  Tensor("Invert_3:0", shape=(3, ), dtype=int32)
[-2 -5 -8]

2022-05-25-10-57-57-PythonProgrammingInArticleAd.webp

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK