bundles / scipy latest / scipy / _lib / array_api_extra / _delegation / partition
function
scipy._lib.array_api_extra._delegation:partition
Signature
def partition ( a : Array , kth : int , / , axis : int | None = -1 , * , xp : ModuleType | None = None ) → Array Summary
Return a partitioned copy of an array.
Extended Summary
Creates a copy of the array and partially sorts it in such a way that the value of the element in k-th position is in the position it would be in a sorted array. In the output array, all elements smaller than the k-th element are located to the left of this element and all equal or greater are located to its right. The ordering of the elements in the two partitions on the either side of the k-th element in the output array is undefined.
Parameters
a: ArrayInput array.
kth: intElement index to partition by.
axis: int, optionalAxis along which to partition. The default is
-1(the last axis). IfNone, the flattened array is used.xp: array_namespace, optionalThe standard-compatible namespace for
x. Default: infer.
Returns
: partitioned_arrayArray of the same type and shape as
a.
Notes
If xp implements partition or an equivalent function (e.g. topk for torch), complexity will likely be O(n). If not, this function simply calls xp.sort and complexity is O(n log n).
Aliases
-
scipy.differentiate.xpx.partition