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.wherewill choose an output shape from the shapes ofcondition,x, andythat all three shapes are broadcastable to.
The
conditiontensor acts as a mask that chooses whether the corresponding element / row in the output should be taken fromx(if the elemment incondition is True) ory` (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