Return a partitioned copy of an array. 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 t
(a, kth, axis=-1, kind='introselect', order=None)
| 731 | |
| 732 | @array_function_dispatch(_partition_dispatcher) |
| 733 | def partition(a, kth, axis=-1, kind='introselect', order=None): |
| 734 | """ |
| 735 | Return a partitioned copy of an array. |
| 736 | |
| 737 | Creates a copy of the array and partially sorts it in such a way that |
| 738 | the value of the element in k-th position is in the position it would be |
| 739 | in a sorted array. In the output array, all elements smaller than the k-th |
| 740 | element are located to the left of this element and all equal or greater |
| 741 | are located to its right. The ordering of the elements in the two |
| 742 | partitions on the either side of the k-th element in the output array is |
| 743 | undefined. |
| 744 | |
| 745 | Parameters |
| 746 | ---------- |
| 747 | a : array_like |
| 748 | Array to be sorted. |
| 749 | kth : int or sequence of ints |
| 750 | Element index to partition by. The k-th value of the element |
| 751 | will be in its final sorted position and all smaller elements |
| 752 | will be moved before it and all equal or greater elements behind |
| 753 | it. The order of all elements in the partitions is undefined. If |
| 754 | provided with a sequence of k-th it will partition all elements |
| 755 | indexed by k-th of them into their sorted position at once. |
| 756 | |
| 757 | axis : int or None, optional |
| 758 | Axis along which to sort. If None, the array is flattened before |
| 759 | sorting. The default is -1, which sorts along the last axis. |
| 760 | kind : {'introselect'}, optional |
| 761 | Selection algorithm. Default is 'introselect'. |
| 762 | order : str or list of str, optional |
| 763 | When `a` is an array with fields defined, this argument |
| 764 | specifies which fields to compare first, second, etc. A single |
| 765 | field can be specified as a string. Not all fields need be |
| 766 | specified, but unspecified fields will still be used, in the |
| 767 | order in which they come up in the dtype, to break ties. |
| 768 | |
| 769 | Returns |
| 770 | ------- |
| 771 | partitioned_array : ndarray |
| 772 | Array of the same type and shape as `a`. |
| 773 | |
| 774 | See Also |
| 775 | -------- |
| 776 | ndarray.partition : Method to sort an array in-place. |
| 777 | argpartition : Indirect partition. |
| 778 | sort : Full sorting |
| 779 | |
| 780 | Notes |
| 781 | ----- |
| 782 | The various selection algorithms are characterized by their average |
| 783 | speed, worst case performance, work space size, and whether they are |
| 784 | stable. A stable sort keeps items with the same key in the same |
| 785 | relative order. The available algorithms have the following |
| 786 | properties: |
| 787 | |
| 788 | ================= ======= ============= ============ ======= |
| 789 | kind speed worst case work space stable |
| 790 | ================= ======= ============= ============ ======= |
no test coverage detected
searching dependent graphs…