Tensorflow:如何以保持 2D 张量形状的方式使用 boolean_mask

当我使用 tf.boolean_mask 时,结果是扁平化的。


tensor7 = tf.constant( [[ 0,  1,  2,  3, -1],[ 2,  3,  4, -1, -1],[ 3,  6,  5,  4,  3]], tf.int64)

mask7 = tf.constant([[ True,  True,  True,  True, False],  [ True,  True,  True, False, False], [ True,  True,  True,  True,  True]], tf.bool)

result7=tf.boolean_mask(tensor7, mask7, axis=0)  


with tf.Session() as sess:

    print(sess.run([ result7 ]))

数组([0, 1, 2, 3, 2, 3, 4, 3, 6, 5, 4, 3])]


有没有办法使用它来保留原始的 3 数组形状?各个阵列的形状应该改变,因为它们现在更短了。我正在寻找这样的东西


[数组([[ 0, 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 6, 5, 4, 3]])


守候你守候我
浏览 171回答 1
1回答

白猪掌柜的

您的期望在逻辑上可能不合理,正如在与您的问题类似的功能请求中进一步指出的那样。您需要为张量提供动态形状,这在 TensorFlow 中只有有限的支持(例如Ragged Tensors)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python