【tensorflow】tf-tf.where(condition, x, y, name)
def where_v2(condition, x=None, y=None, name=None):
- 参数只有condition;
tf.where([True,False,False,True])
return: <tf.Tensor:shape=(2,1),dtype=int64,
numpy=array([[0],[3]])
tf.where([[True,False],[False,True]])*tf.Tensor:shape=(2,2),dtype=int64,
numpy=array([[0,0],[1,1]])>
tf.where([[[True,False],[False,True],[True,True]]])
tf.Tensor:shape=(4,3),dtype=int64,
numpy=array([[0,0,0],[0,1,1],[0,2,0],[0,2,1]])
Theconditiontensor actssa mask that chooses whether the corresponding
element/row in the output should be taken fromx
(if the elemment inconditionisTrue) ory`(if it is false).
*存在条件的时候如果条件是true,返回x,*否则返回y
tf.where([True, False, False, True], [1,2,3,4], [100,200,300,400])<tf.Tensor: shape=(4,), dtype=int32, numpy=array([ 1, 200, 300, 4],dtype=int32)
两个数组[1, 2, 3, 4] and [100, 200, 300, 400]
对照条件[True, False, False, True],可知条件数组为True下标为[0, 3] 所以选择x中的元素1和元素4,剩下从y矩阵选择;
tf.where([True, False, False, True], 1, 100)<tf.Tensor: shape=(4,), dtype=int32, numpy=array([ 1, 100, 100, 1],dtype=int32)>
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
