tensorflow中的boolean_mask
将mask中所有为true的抽取出来,放到一起,这里从n维降到1维度
tensor = [[1, 2], [3, 4], [5, 6]]
import numpy as np
mask=np.array([[True,True],[False,True],[False,False]])
z=tf.boolean_mask(tensor, mask)
sess.run(z)
array([1, 2, 4])
tensor = [[[1, 2], [3, 4], [5, 6]],[[1, 2], [3, 4], [5, 6]]]
import numpy as np
mask=np.array([[[True,True],[False,True],[False,False]],[[True,True],[False,True],[False,False]]])
z=tf.boolean_mask(tensor, mask)
sess.run(z)
array([1, 2, 4, 1, 2, 4])