📜  Python – Tensorflow bitwise.bitwise_or() 方法

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

Python – Tensorflow bitwise.bitwise_or() 方法

Tensorflow bitwise.bitwise_or()方法执行 bitwise_or 操作并返回那些在 a 或 b 中设置(1)或在两者中设置的位。该操作是在 a 和 b 的表示上完成的。
该方法属于按位模块。

让我们通过几个例子来看看这个概念:
示例 1:
# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant a and b 
a = tf.constant(43, dtype = tf.int32) 
b = tf.constant(5, dtype = tf.int32) 
  
# Applying the bitwise_or function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_or(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
    print("Input 2", b)
    print(sess.run(b))
    print("Output: ", c)
    print(sess.run(c))

输出:

Input 1 Tensor("Const_22:0", shape=(), dtype=int32)
43
Input 2 Tensor("Const_23:0", shape=(), dtype=int32)
5
Output:  Tensor("BitwiseOr_1:0", shape=(), dtype=int32)
47

示例 2:

# Importing the Tensorflow library 
import tensorflow as tf 
  
# A constant vector of size 2 
a = tf.constant([1, 6], dtype = tf.int32) 
b = tf.constant([2, 5], dtype = tf.int32) 
  
# Applying the bitwise_or function 
# storing the result in 'c' 
c = tf.bitwise.bitwise_or(a, b) 
  
# Initiating a Tensorflow session 
with tf.Session() as sess:
    print("Input 1", a)
    print(sess.run(a))
    print("Input 2", b)
    print(sess.run(b))
    print("Output: ", c)
    print(sess.run(c))

输出:

Input 1 Tensor("Const_20:0", shape=(2, ), dtype=int32)
[1 6]
Input 2 Tensor("Const_21:0", shape=(2, ), dtype=int32)
[2 5]
Output:  Tensor("BitwiseOr:0", shape=(2, ), dtype=int32)
[3 7]