Python Tensorflow:如何以保持二维张量形状的方式使用布尔_掩码
当我使用tf.boolean_mask时,结果是平坦的Python Tensorflow:如何以保持二维张量形状的方式使用布尔_掩码,python,tensorflow,Python,Tensorflow,当我使用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
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]]
你的期望可能在逻辑上不合理,正如你的问题进一步指出的那样。你需要有张量的动态形状,它在TensorFlow中只有有限的支持(例如).我尝试使用参差不齐的张量,但这只会引发另一个错误。张量可以使用动态形状,但不是为Tensorflow中的每个函数都准备好。标记为适合此特定实例。