查找一維張量中的唯一元素。
用法
tf.unique_with_counts(
x, out_idx=tf.dtypes.int32, name=None
)
參數
返回
-
Tensor
對象的元組(y、idx、count)。 -
y
一個Tensor
。具有與x
相同的類型。 -
idx
Tensor
類型為out_idx
。 -
count
Tensor
類型為out_idx
。
此操作返回一個張量 y
,其中包含 x
的所有唯一元素,這些元素的排序順序與它們在 x
中出現的順序相同。此操作還返回一個與 x
大小相同的張量 idx
,其中包含唯一輸出 y
中每個 x
值的索引。最後,它返回第三個張量 count
,其中包含 x
中 y
的每個元素的計數。換一種說法:
y[idx[i]] = x[i] for i in [0, 1,...,rank(x) - 1]
例如:
# tensor 'x' is [1, 1, 2, 4, 4, 4, 7, 8, 8]
y, idx, count = unique_with_counts(x)
y ==> [1, 2, 4, 7, 8]
idx ==> [0, 0, 1, 2, 2, 2, 3, 4, 4]
count ==> [2, 1, 3, 1, 2]
相關用法
- Python tf.unique用法及代碼示例
- Python tf.unstack用法及代碼示例
- Python tf.unravel_index用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.distribute.OneDeviceStrategy.experimental_distribute_values_from_function用法及代碼示例
- Python tf.math.special.fresnel_cos用法及代碼示例
- Python tf.keras.applications.inception_resnet_v2.preprocess_input用法及代碼示例
- Python tf.compat.v1.layers.conv3d用法及代碼示例
- Python tf.Variable.__lt__用法及代碼示例
- Python tf.keras.metrics.Mean.merge_state用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.unique_with_counts。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。