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


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

張量流bitwise.right_shift()方法對輸入b定義的輸入a執行right_shift操作,並返回新常數。該操作在a和b的表示上完成。
該方法屬於按位模塊。

用法:tf.bitwise.right_shift( 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(256, dtype = tf.int32) 
b = tf.constant(1, dtype = tf.int32)   
  
# Applying the right_shift() function  
# storing the result in 'c'  
c = tf.bitwise.right_shift(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_57:0", shape=(), dtype=int32)
256
Input 2 Tensor("Const_58:0", shape=(), dtype=int32)
1
Output: Tensor("RightShift_3:0", shape=(), dtype=int32)
128

範例2:

# Importing the Tensorflow library  
import tensorflow as tf  
  
# A constant a and b 
a = tf.constant([8, 16, 32], dtype = tf.int32) 
b = tf.constant([2, 2, 3], dtype = tf.int32)   
  
# Applying the right_shift() function  
# storing the result in 'c'  
c = tf.bitwise.right_shift(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_53:0", shape=(3, ), dtype=int32)
[ 8 16 32]
Input 2 Tensor("Const_54:0", shape=(3, ), dtype=int32)
[2 2 3]
Output: Tensor("RightShift_1:0", shape=(3, ), dtype=int32)
[2 4 4]



相關用法


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