当我使用 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]])
1 回答

白猪掌柜的
TA贡献1893条经验 获得超10个赞
您的期望在逻辑上可能不合理,正如在与您的问题类似的功能请求中进一步指出的那样。您需要为张量提供动态形状,这在 TensorFlow 中只有有限的支持(例如Ragged Tensors)。
添加回答
举报
0/150
提交
取消