Skip to content

Commit f381282

Browse files
kavyasrinetabhinavarora
authored andcommitted
Added documentation for topk (#6861)
1 parent fba6a10 commit f381282

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

python/paddle/v2/fluid/layers/control_flow.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,30 @@ def max_sequence_len(rank_table):
485485

486486

487487
def topk(input, k):
488+
"""
489+
**topk**
490+
491+
This function performs the operation that selects the k entries in the input
492+
vector and outputs their values and indices as vectors. Thus topk_out[j] is
493+
the j-th largest entry in input, and its index is topk_indices[j]
494+
495+
Args:
496+
input (Variable|list): The input tensor that has all the data.
497+
k (int): The number of top elements that the function will pick.
498+
499+
Returns:
500+
Variable: The variable of type array that contains the k largest entries
501+
from input.
502+
Variable: The variable of type array that contains the indices of k
503+
largest entries from input.
504+
505+
Examples:
506+
.. code-block:: python
507+
508+
x = fluid.layers.data(name='x', shape=[10])
509+
k = 5
510+
array = fluid.layers.topk(x, k)
511+
"""
488512
helper = LayerHelper('topk', **locals())
489513
topk_out = helper.create_tmp_variable(dtype=input.data_type)
490514
topk_indices = helper.create_tmp_variable(dtype='int64')

0 commit comments

Comments
 (0)