📜  Python – TensorFlow bitwise.right_shift() 方法

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

Python – TensorFlow bitwise.right_shift() 方法

Tensorflow bitwise.right_shift()方法对输入 b 定义的输入 a 执行 right_shift 操作并返回新常量。该操作是在 a 和 b 的表示上完成的。
该方法属于按位模块。

让我们通过几个例子来看看这个概念:
示例 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]