Search code examples
pythontensorflowbooleanmask

output 2d boolean masked value by tensorflow


I have a [n,m] input and [n,m] boolean mask. How could I output a [n,x] filtered matrix, instead of [x] array?
For example, input

x = [[1,2,3],[4,5,6]]

and a boolean mask

bm = [[1,0,1],[1,0,0]]

I tried to use tf.boolean_mask() and I got [1,3,4]. How could I get a 2D result like

result =  [[1,3],[4]]

Thanks!


Solution

  • This operation could not exist in TF because TF operates on the tensors and returns tensors. The result you received has different number of elements and not a tensor.