計算 a
和 b
的最後一維中元素的集合交集。
用法
tf.sets.intersection(
a, b, validate_indices=True
)
參數
-
a
Tensor
或SparseTensor
與b
的類型相同。如果稀疏,則索引必須按行優先順序排序。 -
b
Tensor
或SparseTensor
與a
的類型相同。如果稀疏,則索引必須按行優先順序排序。 -
validate_indices
是否驗證a
和b
中稀疏索引的順序和範圍。
返回
-
一個
SparseTensor
,其形狀與a
和b
的等級相同,並且除了最後一個維度之外的所有維度都相同。沿最後一個維度的元素包含交叉點。
除了a
和b
的最後一個維度之外的所有維度都必須匹配。
例子:
import tensorflow as tf
import collections
# Represent the following array of sets as a sparse tensor:
# a = np.array([[{1, 2}, {3}], [{4}, {5, 6}]])
a = collections.OrderedDict([
((0, 0, 0), 1),
((0, 0, 1), 2),
((0, 1, 0), 3),
((1, 0, 0), 4),
((1, 1, 0), 5),
((1, 1, 1), 6),
])
a = tf.sparse.SparseTensor(list(a.keys()), list(a.values()),
dense_shape=[2,2,2])
# b = np.array([[{1}, {}], [{4}, {5, 6, 7, 8}]])
b = collections.OrderedDict([
((0, 0, 0), 1),
((1, 0, 0), 4),
((1, 1, 0), 5),
((1, 1, 1), 6),
((1, 1, 2), 7),
((1, 1, 3), 8),
])
b = tf.sparse.SparseTensor(list(b.keys()), list(b.values()),
dense_shape=[2, 2, 4])
# `tf.sets.intersection` is applied to each aligned pair of sets.
tf.sets.intersection(a, b)
# The result will be equivalent to either of:
#
# np.array([[{1}, {}], [{4}, {5, 6}]])
#
# collections.OrderedDict([
# ((0, 0, 0), 1),
# ((1, 0, 0), 4),
# ((1, 1, 0), 5),
# ((1, 1, 1), 6),
# ])
相關用法
- Python tf.sets.union用法及代碼示例
- Python tf.sets.difference用法及代碼示例
- Python tf.searchsorted用法及代碼示例
- Python tf.sequence_mask用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.strings.substr用法及代碼示例
- Python tf.strings.reduce_join用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.mask用法及代碼示例
- Python tf.strings.regex_full_match用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.strings.regex_replace用法及代碼示例
- Python tf.signal.overlap_and_add用法及代碼示例
- Python tf.strings.length用法及代碼示例
- Python tf.strided_slice用法及代碼示例
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.strings.bytes_split用法及代碼示例
- Python tf.summary.text用法及代碼示例
- Python tf.shape用法及代碼示例
- Python tf.sparse.expand_dims用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.sets.intersection。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。