2020-06-05-tensorflow2-tf.where说
2020-06-08 本文已影响0人
logi
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]] )
![](https://img.haomeiwen.com/i10188726/923b54d72a095992.png)