如何使用张量流比较两个数组? [英] How to compare two arrays using tensorflow?

查看:103
本文介绍了如何使用张量流比较两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要比较两个数组并得到true或false,而不是逐元素结果.我的代码是

I need to compare two arrays and get either true or false,not elementwise result. My code is

X = tf.constant([0.05, 0.10], dtype=tf.float32, shape=[1, 2])
y = tf.constant([0.01, 0.99], dtype=tf.float32, shape=[1, 2])

equality = tf.equal(X, y)

打印[False,False]

prints [False, False]

我的要求是获取true或false,而不是数组.

my requirement is to get true or false, not an array.

推荐答案

假设您要返回 False ,如果您的任何值不相等,则可以使用 reduce_all 操作:

Assuming that you want to return False if any of your values are not equal then you can use the reduce_all operation:

equality = tf.math.reduce_all(tf.equal(X, y))

这篇关于如何使用张量流比较两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆