很遗憾,我找不到实现以下功能的函数:
输入:
- test:target 中可能存在的值张量
- 目标:张量值
输出:
- 输出: bool 张量,形状与测试相同。
output[i] = targets.contains(test[i])
说白了:我需要测试一个 Tensor 的元素是否包含在另一个 Tensor 中。
最佳答案
答案更新于 2020-03-23 以使用 setdiff。
您想使用 tf.sets.difference
.
给定两个张量test
和target
,
not_in_target = tf.sets.difference(test, target)
not_in_target
将包含测试中不在目标中的项目。如果你想在目标中找到那些是的,你可以再次设置差异:
tests_in_target = tf.listdiff(test, not_in_target)
其中包含来自 test
的项目,这些项目已在 target
张量中成功找到。
关于python - 检查值是否包含在张量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34598204/