TensorFlow入门基础知识(九)tf.where的用法

版权声明:转载请标明附带连接标明出处 https://blog.csdn.net/Hollake/article/details/79825643

tf.where(input, name=None)这是官网文档中给的例子

Args:

  • input: A Tensor of type bool.
  • name: A name for the operation (optional).

Returns:

Tensor of type int64.

解释的不是很清楚,我注释了一下

# 'input' tensor is [[True, False]
#                    [True, False]]
# 'input' has two true values, so output has two coordinates.
# 'input' has rank of 2, so coordinates have two indices.
where(input) ==> [[0, 0],        #坐标0的地方 值为真
                  [1, 0]]        #坐标1的地方  值为真

# `input` tensor is [[[True, False]
#                     [True, False]]
#                    [[False, True]
#                     [False, True]]
#                    [[False, False]
#                     [False, True]]]        #这是三阶的
# 'input' has 5 true values, so output has 5 coordinates.
# 'input' has rank of 3, so coordinates have three indices.
where(input) ==> [[0, 0, 0],        #表示在(0,0)的位置0的地方为真
                  [0, 1, 0],        #表示在(0,1)的位置0的地方为真
                  [1, 0, 1],        #表示在(1,0)的位置1的地方为真
                  [1, 1, 1],        #表示在(1,1)的位置1的地方为真
                  [2, 1, 1]]        #表示在(2,1)的位置1的地方为真
因为(2,0)的位置为假,所以是5*3的向量

猜你喜欢

转载自blog.csdn.net/Hollake/article/details/79825643