Python - tensorflow.boolean_mask() method Last Updated : 24 Feb, 2023 Comments Improve Suggest changes Like Article Like Report TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. boolean_mask() is method used to apply boolean mask to a Tensor. Syntax: tensorflow.boolean_mask(tensor, mask, axis, name) Parameters: tensor: It's a N-dimensional input tensor.mask: It's a boolean tensor with k-dimensions where k<=N and k is known statically.axis: It's a 0-dimensional tensor which represents the axis from which mask should be applied. Default value for axis is zero and k+axis<=N.name: It's an optional parameter that defines the name for the operation. Return: It returns (N-K+1)-dimensional tensor which have the values that are populated against the True values in mask. Example 1: In this example input is 1-D. Python3 # importing the library import tensorflow as tf # initializing the inputs tensor = [1,2,3] mask = [False, True, True] # printing the input print('Tensor: ',tensor) print('Mask: ',mask) # applying the mask result = tf.boolean_mask(tensor, mask) # printing the result print('Result: ',result) Output: Tensor: [1, 2, 3] Mask: [False, True, True] Result: tf.Tensor([2 3], shape=(2,), dtype=int32) Example 2: In this example 2-D input is taken. Python3 # importing the library import tensorflow as tf # initializing the inputs tensor = [[1, 2], [10, 14], [9, 7]] mask = [False, True, True] # printing the input print('Tensor: ',tensor) print('Mask: ',mask) # applying the mask result = tf.boolean_mask(tensor, mask) # printing the result print('Result: ',result) Output: Tensor: [[1, 2], [10, 14], [9, 7]] Mask: [False, True, True] Result: tf.Tensor( [[10 14] [ 9 7]], shape=(2, 2), dtype=int32) Comment More infoAdvertise with us Next Article Python - tensorflow.boolean_mask() method aman neekhara Follow Improve Article Tags : Python Python-Tensorflow Practice Tags : python Similar Reads 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 2 min read 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 logi 2 min read 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 2 min read Python - Tensorflow bitwise.invert() method 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 2 min read Python | Tensorflow logical_xor() 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_xor() [alias tf.math.logical_xor] provides support for the logical 2 min read 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 2 min read Python - Tensorflow bitwise.bitwise_and() method Tensorflow bitwise.bitwise_and() method performs the bitwise_and operation and return those bits set, that are set(1) in both a and b. The operation is done on the representation of a and b. This method belongs to bitwise module. Syntax: tf.bitwise.bitwise_and( a, b, name=None) Arguments a: This mus 2 min read Tensorflow bitwise.bitwise_xor() method - Python Tensorflow bitwise.bitwise_xor() method performs the bitwise_xor operation and the result will set those bits, that are different in a and b. The operation is done on the representation of a and b. This method belongs to bitwise module. Syntax: tf.bitwise.bitwise_xor(a, b, name=None) Arguments a: Th 2 min read Python - tensorflow.cond() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. cond() return true_fn() if the predicate pred is true otherwise it returns false_fn(). Syntax: tensorflow.cond( pred, true_fn, false_fn, name ) Parameters: pred: It is a 1 min read Python - Tensorflow bitwise.left_shift() method Tensorflow bitwise.left_shift() method performs the left_shift operation on input a defined by input b and return the new constant. The operation is done on the representation of a and b. This method belongs to bitwise module. Syntax: tf.bitwise.left_shift( a, b, name=None) Arguments a: This must be 2 min read Like