# add numpy.partition like functionality ## Overview What's up awesome ndarray community! I searched through old issues and found the related issues below. There were couple of discussions and PRs, but currently, it seems like ndarray and ndarray-stats lack several key sorting and searching operations that are available in NumPy. ## Start with partitioning: API is gonna be like.. ```rust impl<A, D> ArrayBase<S, D> where A: Ord, D: Dimension, { /// Partially sorts the array around the k-th element. /// /// Similar to NumPy's `partition`. Returns a new array where: /// - All elements smaller than the k-th element are to its left /// - All elements equal or greater than the k-th element are to its right /// - The ordering within each partition is undefined pub fn partition(&self, kth: usize) -> Array<A, D> { ... } /// Returns the indices that would partition the array. /// /// Similar to NumPy's `argpartition`. Returns indices that would partition /// the array around the k-th element. pub fn argpartition(&self, kth: usize) -> Array<usize, D> { ... } } ``` ## Note - I searched the codebase thoroughly and started implementing this feature, but there might already be an existing implementation that I missed. If that's the case, please let me know! - will open draft PR soon! ## Related Issues - #416 - #649 - #1145 - (might be more) ## References - [NumPy documentation for argsort](https://numpy.org/doc/stable/reference/generated/numpy.argsort.html) - [NumPy documentation for partition](https://numpy.org/doc/stable/reference/generated/numpy.partition.html) - [NumPy documentation for argwhere](https://numpy.org/doc/stable/reference/generated/numpy.argwhere.html) - [NumPy documentation for where](https://numpy.org/doc/stable/reference/generated/numpy.where.html)