检查值是否包含在张量中
Check if values are contained within a Tensor
很遗憾,我找不到实现以下功能的函数:
输入:
- test: target
中可能存在的张量值
- 目标:张量值
输出:
- 输出:布尔张量,与测试形状相同。
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
张量中成功找到的项目。
很遗憾,我找不到实现以下功能的函数:
输入:
- test: target 中可能存在的张量值
- 目标:张量值
输出:
- 输出:布尔张量,与测试形状相同。
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
张量中成功找到的项目。