tf.while_loop,tf.cast 转换数据类型。

tf.while_loop 可以这样理解

loop = []
while cond(loop):
    loop = body(loop)

即loop参数先传入cond 判断条件是否成立,成立之后,把 loop参数传入body 执行操作, 然后返回 操作后的 loop 参数,即loop参数已被更新,再把更新后的参数传入cond, 依次循环,直到不满足条件。

tf.cast 转换数据类型。

a = tf.constant([0, 2, 0, 4, 2, 2], dtype='int32')
print(a)
# <tf.Tensor 'Const_1:0' shape=(6,) dtype=int32>

b = tf.cast(a, 'float32')
print(b)
# <tf.Tensor 'Cast:0' shape=(6,) dtype=float32>

tf.greater

首先张量x和张量y的尺寸要相同,输出的tf.greater(x, y)也是一个和x,y尺寸相同的张量。如果x的某个元素比y中对应位置的元素大,则tf.greater(x, y)对应位置返回True,否则返回False。

tf.less
tensorflow的内置函数,写x,y都是一个tensor,返回值是一个bool型的tensor.[逐元素返回是否x<y]

猜你喜欢

转载自blog.csdn.net/dihe874981/article/details/84337173