tf.boolean_mask
简单解释
用一个mask数组和输入的tensor做与操作,忽略为0的值。
api
定义在tensorflow/python/ops/array_ops.py
1 | tf.boolean_mask( |
代码示例
1 | import tensorflow as tf |
输出如下:
a: [1 2 3]
b: [2. 1. 4.]
c: [2. 1. 0.]
d: [2. 0. 4.]
e: [0. 1. 4.]
f: [0. 1. 0.]
g: [0. 0. 0.]
tf.boolean(a, b):
[1 2 3]
tf.boolean(a, c):
[1 2]
tf.boolean(a, d):
[1 3]
tf.boolean(a, e):
[2 3]
tf.boolean(a, f):
[2]
tf.boolean(a, g):
[]
参考文献
1.http://landcareweb.com/questions/27920/zai-tensorflowzhong-ru-he-cong-pythonde-zhang-liang-zhong-huo-qu-fei-ling-zhi-ji-qi-suo-yin
2.https://www.tensorflow.org/api_docs/python/tf/boolean_mask