tensorflow函数_tf.where()

1.第一种用法:tf.where(input, name=None):返回输入矩阵中true的位置
For example:
(1)‘input’ tensor is [[True, False]
[True, False]]
input里面有两个true,所以返回两行(两个位置信息)
where(input) ==> [[0, 0],
[1, 0]]

(2)input tensor is [[[True, False]
[True, False]]
[[False, True]
[False, True]]
[[False, False]
[False, True]]]
里面有5个true,所以返回5个位置信息。
第一位是0,1,2号矩阵,第二三位是在每个矩阵中的位置信息
where(input) ==> [[0, 0, 0],
[0, 1, 0],
[1, 0, 1],
[1, 1, 1],
[2, 1, 1]]
2.第二种用法:tf.where(input, a,b),其中a,b均为尺寸一致的tensor,作用是将a中对应input中true的位置的元素值不变,其余元素进行替换,替换成b中对应位置的元素值。
for example:
tensorflow函数_tf.where()