API文档:https://www.tensorflow.org/api_docs/python/tf/where?hl=en
用途
tf.where 通过boolean矩阵的true or false 对候选条件下的两个矩阵进行element选取
tf.where
will choose an output shape from the shapes ofcondition
,x
, andy
that all three shapes are broadcastable to.
The
condition
tensor acts as a mask that chooses whether the corresponding element / row in the output should be taken fromx
(if the elemment incondition is True) or
y` (if it is false).
例子
这里true就选x中的元素,false就选y中的元素
tf.where([[True, False], [False, True]], x=[[1,2],[3,4]] , y=[[5,6],[7,8]] )
image.png
网友评论