Reputation: 255
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!
Upvotes: 2
Views: 633
Reputation: 222541
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.
Upvotes: 1
Reputation: 2996
There's no way to do this in TF. However, you can consider using Masked Array in numpy. You can do something like
>>> import numpy as np, numpy.ma as ma
>>> x = ma.array([1., -1., 3., 4., 5., 6.], mask=[0,0,0,0,1,0])
>>> y = ma.array([1., 2., 0., 4., 5., 6.], mask=[0,0,0,0,0,1])
>>> print np.sqrt(x/y)
[1.0 -- -- 1.0 -- --]
Upvotes: 0