tensorflow topk

来源:互联网 发布:淘宝直通车步骤 编辑:程序博客网 时间:2024/05/16 12:48

Tensorflow topk:

函数定义:

def top_k(input, k=1, sorted=True, name=None):

“”“

  Args:
    input: 1-D or higher `Tensor` with last dimension at least `k`.
    k: 0-D `int32` `Tensor`.  Number of top elements to look for along the last
      dimension (along each row for matrices).
    sorted: If true the resulting `k` elements will be sorted by the values in
      descending order.
    name: Optional name for the operation.


  Returns:
    values: The `k` largest elements along each last dimensional slice.
    indices: The indices of `values` within the last dimension of `input`.
  """

此函数的功能是求取1-D 或N-D Tensor的最低维度的前k个最大的值,返回值为两个Tuple,其中values是前k个最大值的Tuple,indices是各个值对应的下标,默认返回结果是从大到小排序的。


使用示例:

topk = tf.nn.top_k(probability_array, 3, name="topk")


此函数在机器学习中经常使用

0 0
原创粉丝点击