import tensorflow as tf
# input is a tensor
output = tf.nn.top_k(input, k)
# the output is k tuple (values, indices)
# tensorflow 获取前 k 个最大值
values = tf.nn.top_k(input, k).values # 得到前k 个最大值
indices = tf.nn.top_k(input, k).indices # 得到前k 个最大值所对应的索引
# tensorflow 获取前 k 个最小值
values = tf.nn.top_k(-input, k).values # 得到前k 个最小值
indices = tf.nn.top_k(-input, k).indices # 得到前k 个最小值所对应的索引