Saturday, November 22, 2025
HomeLanguagesPython – tensorflow.math.equal()

Python – tensorflow.math.equal()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

equal() is used to perform element by equality comparison.  It performs argument broadcasting before applying the comparison.

Syntax: tensorflow.math.equal( x, y, name)

Parameters:

  • x: It can be a tensor or sparse tensor or indexed slices.
  • y: It can be a tensor or sparse tensor or indexed slices.
  • name(optional): It defines the name for the operation.

Returns: It returns a bool tensor.

Example 1: In this example broadcasting is performed.

Python3




# importing the library
import tensorflow as tf
  
# Initializing the input tensor
a = tf.constant([6, 8, 12, 2], dtype = tf.float64)
b = (2)
  
# Printing the input tensor
print('a: ', a)
print('b: ', b)
  
# Performing equality comparison
res = tf.math.equal(x = a, y = b)
  
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([ 6.  8. 12.  2.], shape=(4, ), dtype=float64)
b:  2
Result:  tf.Tensor([False False False  True], shape=(4, ), dtype=bool)

Example 2:

Python3




# importing the library
import tensorflow as tf
  
# Initializing the input tensor
a = tf.constant([6, 8, 12, 4], dtype = tf.float64)
b = tf.constant([2, 8, 12, 7],  dtype = tf.float64)
  
# Printing the input tensor
print('a: ', a)
print('b: ', b)
  
# Performing equality comparison
res = tf.math.equal(x = a, y = b)
  
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([ 6.  8. 12.  4.], shape=(4, ), dtype=float64)
b:  tf.Tensor([ 2.  8. 12.  7.], shape=(4, ), dtype=float64)
Result:  tf.Tensor([False  True  True False], shape=(4, ), dtype=bool)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS