访问量: 10 次浏览
bitwise.invert() 方法Tensorflow bitwise.invert() 方法执行反转操作,其结果是将比特反转,如0到1,1到0。
该方法属于比特模块。
语法:
tf.bitwise.invert( a, name=None)
参数
返回:
它返回一个具有与a相同类型的张量。
让我们借助几个例子来看看这个概念。
示例 1:
import tensorflow as tf
# A constant a
a = tf.constant(6, dtype = tf.int32)
# Applying the invert function
# storing the result in 'c'
c = tf.bitwise.invert(a)
# Initiating a Tensorflow session
with tf.Session() as sess:
print("Input 1", a)
print(sess.run(a))
print("Output: ", c)
print(sess.run(c))
输出:
Input 1 Tensor("Const_40:0", shape=(), dtype=int32)
6
Output: Tensor("Invert_4:0", shape=(), dtype=int32)
-7
示例 2:
import tensorflow as tf
# A constant a
a = tf.constant([1, 4, 7], dtype = tf.int32)
# Applying the invert function
# storing the result in 'c'
c = tf.bitwise.invert(a)
# Initiating a Tensorflow session
with tf.Session() as sess:
print("Input 1", a)
print(sess.run(a))
print("Output: ", c)
print(sess.run(c))
输出:
Input 1 Tensor("Const_39:0", shape=(3, ), dtype=int32)
[1 4 7]
Output: Tensor("Invert_3:0", shape=(3, ), dtype=int32)
[-2 -5 -8]