📜  Python - tensorflow.math.equal()

📅  最后修改于: 2022-05-13 01:54:44.758000             🧑  作者: Mango

Python - tensorflow.math.equal()

TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

equal()用于通过相等比较来执行元素。它在应用比较之前执行参数广播。

示例 1:在此示例中执行广播。

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)


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)


输出:

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

示例 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)

输出:

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)