當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Tensorflow bitwise.bitwise_or()用法及代碼示例

張量流bitwise.bitwise_or()方法執行bitwise_or運算,並返回a中或b中或兩者中都為set(1)的那些位集。該操作在a和b的表示上完成。
該方法屬於按位模塊。

用法:tf.bitwise.bitwise_or( a, b, name=None)

爭論

  • a:它必須是張量,應該來自以下類型之一:int8,int16,int32,int64,uint8,uint16,uint32,uint64。
  • b:這也應該是張量,類型與a相同。
  • 名稱:這是可選參數,這是操作的名稱。

返回:它返回與a和b具有相同類型的Tensor。

讓我們借助幾個示例來了解這個概念:
範例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]



相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 Python – Tensorflow bitwise.bitwise_or() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。