如何比较张量流中的两个张量(不是元素而是张量), 例如:
x = [[1, 2, 3, 4], [0, 0, 0, 0]]
y = [0, 0, 0, 0]
预期:
not_equal(x, y) --> [True, False]
tf.not_equal(x,y)返回:
[[True, True, True, True], [False, False, False, False]]
答案 0 :(得分:1)
这是我实施它的方式:
y = tf.constant([0, 0, 0, 0])
not_equal_t = tf.not_equal(y, x)
reduce_t = tf.reduce_all(not_equal_t, axis=2) --> This will return the [True, False] that I looked for
# The rest will return the values
where_t = tf.where(reduce_t)
gather_t = tf.gather_nd(x, where_t)
答案 1 :(得分:0)
在tensorflow 2中,您可以先将张量转换为numpy数组,然后使用np.array_equal.
t1 = t1.numpy()
t2 = t2.numpy()
res = np.array_equal(t1, t2)