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")
此函数在机器学习中经常使用