TensorFlow函数:tf.unique_with_counts

2018-04-12 10:24 更新

tf.unique_with_counts函数

tf.unique_with_counts(
    x,
    out_idx=tf.int32,
    name=None
)

参见指南:张量变换>分割和连接

在一维张量中找到唯一的元素.

该操作返回一个张量 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]

函数参数:

  • x:一个 Tensor,是 1-d 的.
  • out_idx:可选的 tf.DType 来自:tf.int32, tf.int64;默认为 tf.int32.
  • name:操作的名称(可选).

函数返回值:

Tensor 对象的元组(y,idx,count).

  • y:一个 Tensor,与 x 类型相同.
  • idx:一个 out_idx 类型的 Tensor.
  • count:一个 out_idx 类型的 Tensor.
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号