用于 float 的 Tensorflow 按位非运算符

标签 tensorflow bit-manipulation

我有一个 Tensorflow bool 向量,我需要对其进行按位反转,以使所有 0(假)值变为 1(真),反之亦然。 tf.logical_not存在,但它只需要 bool 向量。是否存在对整数或 float 向量执行此操作的 Tensorflow,这样我就不需要重铸我的张量?

最佳答案

TensorFlow 不包含用于执行按位非运算的特定运算符,但您可以使用 tf.bitcast() 对其进行模拟和整数的算术运算。例如,以下将反转单个浮点值中的位:

input_value = tf.constant(37.0)

bitcast_to_int32 = tf.bitcast(input_value, tf.int32)

invert_bits = tf.constant(-1) - bitcast_to_int32

bitcast_to_float = tf.bitcast(invert_bits, tf.float32)

您可以使用 this answer 确认输入和输出按位取反将浮点值转换为二进制。

关于用于 float 的 Tensorflow 按位非运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41970675/

相关文章:

python - 在图像上训练 Keras 模型时,出现错误 "Invalid argument: Attr shrink_axis_mask has value 4294967295 out of range for an int32"

nan - tensorflow NaN 错误?

python - 值错误: Negative dimension size caused by subtracting 22 from 1 for 'conv3d_3/convolution' (op: 'Conv3D' )

c# - 按位移位 - 在 C# 中获得与在 php 中不同的结果

c - 转换位 vector 需要多少个时钟周期?

c - 将位域打包成字节的 C 预处理器宏?

python - Google 的 TensorFlow 中的 Theano Dimshuffle 等效?

java - 如何检测 32 位 int 上的整数溢出?

java - 我需要关于 Bit Twiddling 的帮助

python - tensorflow-gpu 1.8.0 ImportError : libcudnn. so.7:无法打开共享对象文件:没有这样的文件或目录