当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。