Python | Tensorflow logical_not() 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_not() [alias tf.math.logical_not or tf.Tensor.__invert__] provides support for the logical NOT function in Tensorflow. It expects the input of bool type. The input type is tensor and if the input contains more than one element, an element-wise logical NOT is computed,  $ NOT x $ .

Syntax: tf.logical_not(x, name=None) or tf.math.logical_not(x, name=None) or tf.Tensor.__invert__(x, name=None)

Parameters:
x: 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.

Code:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

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

 



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.