【问题标题】:Get rows of tensor that satisfy condition tensorflow获取满足条件 tensorflow 的张量行
【发布时间】:2018-09-02 07:01:11
【问题描述】:
input_mb = tf.placeholder(tf.int32, [None, 166, 1], name="input_minibatch")

假设有上面的代码。我想获取上述小批量张量的行,使得每个检索到的行的第一个元素 == a。我如何在 Tensorflow 中做到这一点?另外,你如何在 Numpy 中做到这一点?

【问题讨论】:

    标签: numpy tensorflow


    【解决方案1】:

    (给定一个值a)

    要在 numpy 中实现这一点,您只需编写:

    selected_rows = myarray[myarray[:,0]== a]
    

    tensorflow 中,使用 tf.where :

    mytensor[tf.squeeze(tf.where(tf.equal(mytensor[:,0],a), None, None))
    

    【讨论】:

      【解决方案2】:

      我会在 tensorflow 上这样做:

      tf.gather(mytensor, tf.squeeze(tf.where(tf.equal(mytensor[:,0],a), None, None)), axis=0)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-19
        • 2018-09-06
        • 2019-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多