dask 2021.10.0

ParametersReturns
topk(a, k, axis=-1, split_every=None)

This performs best when k is much smaller than the chunk size. All results will be returned in a single chunk along the given axis.

Parameters

x: Array :

Data being sorted

k: int :
axis: int, optional :
split_every: int >=2, optional :

See reduce . This parameter becomes very important when k is on the same order of magnitude of the chunk size or more, as it prevents getting the whole or a significant portion of the input array in memory all at once, with a negative impact on network transfer too when running on distributed.

Returns

Selection of x with size abs(k) along the given axis.

Extract the k largest elements from a on the given axis, and return them sorted from largest to smallest. If k is negative, extract the -k smallest elements instead, and return them sorted from smallest to largest.

Examples

This example is valid syntax, but we were not able to check execution
>>> import dask.array as da
... x = np.array([5, 1, 3, 6])
... d = da.from_array(x, chunks=2)
... d.topk(2).compute() array([6, 5])
This example is valid syntax, but we were not able to check execution
>>> d.topk(-2).compute()
array([1, 3])
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /dask/array/reductions.py#1464
type: <class 'function'>
Commit: