Python – Tensorflow bitwise.invert() 方法
Tensorflow bitwise.invert()
方法执行反转操作,结果将反转位,如 0 到 1 和 1 到 0。该操作是在 a 的表示上完成的。
该方法属于按位模块。
Syntax: tf.bitwise.invert( a, name=None)
Arguments
- a: This must be a Tensor.It should be from the one of the following types: int8, int16, int32, int64, uint8, uint16, uint32, uint64.
- name: This is optional parameter and this is the name of the operation.
Return: It returns a Tensor having the same type as a.
让我们通过几个例子来看看这个概念:
示例 1:
示例 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]
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。