MCPcopy
hub / github.com/numpy/numpy / argpartition

Function argpartition

numpy/_core/fromnumeric.py:849–932  ·  view source on GitHub ↗

Perform an indirect partition along the given axis using the algorithm specified by the `kind` keyword. It returns an array of indices of the same shape as `a` that index data along the given axis in partitioned order. Parameters ---------- a : array_like Array

(a, kth, axis=-1, kind='introselect', order=None)

Source from the content-addressed store, hash-verified

847
848@array_function_dispatch(_argpartition_dispatcher)
849def argpartition(a, kth, axis=-1, kind='introselect', order=None):
850 """
851 Perform an indirect partition along the given axis using the
852 algorithm specified by the `kind` keyword. It returns an array of
853 indices of the same shape as `a` that index data along the given
854 axis in partitioned order.
855
856 Parameters
857 ----------
858 a : array_like
859 Array to sort.
860 kth : int or sequence of ints
861 Element index to partition by. The k-th element will be in its
862 final sorted position and all smaller elements will be moved
863 before it and all larger elements behind it. The order of all
864 elements in the partitions is undefined. If provided with a
865 sequence of k-th it will partition all of them into their sorted
866 position at once.
867
868 axis : int or None, optional
869 Axis along which to sort. The default is -1 (the last axis). If
870 None, the flattened array is used.
871 kind : {'introselect'}, optional
872 Selection algorithm. Default is 'introselect'
873 order : str or list of str, optional
874 When `a` is an array with fields defined, this argument
875 specifies which fields to compare first, second, etc. A single
876 field can be specified as a string, and not all fields need be
877 specified, but unspecified fields will still be used, in the
878 order in which they come up in the dtype, to break ties.
879
880 Returns
881 -------
882 index_array : ndarray, int
883 Array of indices that partition `a` along the specified axis.
884 If `a` is one-dimensional, ``a[index_array]`` yields a partitioned `a`.
885 More generally, ``np.take_along_axis(a, index_array, axis=axis)``
886 always yields the partitioned `a`, irrespective of dimensionality.
887
888 See Also
889 --------
890 partition : Describes partition algorithms used.
891 ndarray.partition : Inplace partition.
892 argsort : Full indirect sort.
893 take_along_axis : Apply ``index_array`` from argpartition
894 to an array as if by calling partition.
895
896 Notes
897 -----
898 The returned indices are not guaranteed to be sorted according to
899 the values. Furthermore, the default selection algorithm ``introselect``
900 is unstable, and hence the returned indices are not guaranteed
901 to be the earliest/latest occurrence of the element.
902
903 `argpartition` works for real/complex inputs with nan values,
904 see `partition` for notes on the enhanced sort order and
905 different selection algorithms.
906

Callers

nothing calls this directly

Calls 1

_wrapfuncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…