赞
踩
tensorflow 中tf.equal()用法:
equal(x, y, name=None)
equal,相等的意思。顾名思义,就是判断,x, y 是不是相等,它的判断方法不是整体判断,
而是逐个元素进行判断,如果相等就是True,不相等,就是False。
- import tensorflow as tf
- a = [[1,2,3],[4,5,6]]
- b = [[1,0,3],[1,5,1]]
- with tf.Session() as sess:
- print(sess.run(tf.equal(a,b)))
结果:
- [[ True False True]
- [False True False]]
20210512更新,已经有earge模式,不需要写Session了
- import tensorflow as tf
- tf.enable_eager_execution()
-
-
- inputs = tf.constant([[1,-1,3],
- [5,-1,7]])
-
- tf.equal(inputs, -1)
结果:
<tf.Tensor: id=8, shape=(2, 3), dtype=bool, numpy= array([[False, True, False], [False, True, False]])>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。