codecamp

TensorFlow函数:tf.unique_with_counts

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.
TensorFlow函数:tf.unique
TensorFlow函数:tf.unravel_index
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }