Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.argpartition

numpy.argpartition(a,kth,axis=-1,kind='introselect',order=None)[source]

Perform an indirect partition along the given axis using thealgorithm specified by thekind keyword. It returns an array ofindices of the same shape asa that index data along the givenaxis in partitioned order.

New in version 1.8.0.

Parameters:

a : array_like

Array to sort.

kth : int or sequence of ints

Element index to partition by. The k-th element will be in itsfinal sorted position and all smaller elements will be movedbefore it and all larger elements behind it. The order allelements in the partitions is undefined. If provided with asequence of k-th it will partition all of them into their sortedposition at once.

axis : int or None, optional

Axis along which to sort. The default is -1 (the last axis). IfNone, the flattened array is used.

kind : {‘introselect’}, optional

Selection algorithm. Default is ‘introselect’

order : str or list of str, optional

Whena is an array with fields defined, this argumentspecifies which fields to compare first, second, etc. A singlefield can be specified as a string, and not all fields need bespecified, but unspecified fields will still be used, in theorder in which they come up in the dtype, to break ties.

Returns:

index_array : ndarray, int

Array of indices that partitiona along the specified axis.In other words,a[index_array] yields a partitioneda.

See also

partition
Describes partition algorithms used.
ndarray.partition
Inplace partition.
argsort
Full indirect sort

Notes

Seepartition for notes on the different selection algorithms.

Examples

One dimensional array:

>>>x=np.array([3,4,2,1])>>>x[np.argpartition(x,3)]array([2, 1, 3, 4])>>>x[np.argpartition(x,(1,3))]array([1, 2, 3, 4])
>>>x=[3,4,2,1]>>>np.array(x)[np.argpartition(x,3)]array([2, 1, 3, 4])

Previous topic

numpy.partition

Next topic

numpy.argmax

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp