【问题标题】:Tensorflow: How to convert an integer tensor to the corresponding binary tensorTensorflow:如何将整数张量转换为对应的二进制张量
【发布时间】:2018-06-28 05:29:39
【问题描述】:

我想将整数张量 a_dec=tf.constant([2,7], dtype=tf.int32) 转换为二进制 rank-2 张量,例如:a_bin=tf.constant([[0,1,0],[1,1,1]], dtype=tf.int32)

有什么有效的方法吗?

【问题讨论】:

    标签: tensorflow binary int


    【解决方案1】:

    如果您知道向量的大小n,那么:

    a_bin = tf.mod(tf.bitwise.right_shift(tf.expand_dims(a_dec,1), tf.range(n)), 2)
    

    【讨论】:

    • 感谢您的帮助。我正在使用 TF 1.4 版,它还不支持 tf.bitwise.right_shift()。但这是个好主意。
    • 从 TF 1.5 开始提供,当前版本是 TF 1.8。也许考虑升级。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 2019-05-02
    • 2017-06-14
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多