检查值是否包含在张量中

Check if values are contained within a Tensor

很遗憾,我找不到实现以下功能的函数:

输入:

输出:


说白了:我需要测试一个Tensor的元素是否包含在另一个Tensor中。

答案更新于 2020-03-23 以使用 setdiff。

您想使用 tf.sets.difference.

给定两个张量 testtarget,

not_in_target = tf.sets.difference(test, target)

not_in_target 将包含测试中 不在目标中的 项目。如果你想在目标中找到 的那些,你可以再次设置差异:

tests_in_target = tf.listdiff(test, not_in_target)

然后包含 test 中在 target 张量中成功找到的项目。