Closed
Description
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..
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
- Argmax/margmin for Array1 #416
- Feedback on Ndarray/Ndarray-linalg (from Reddit) #649
- Implementing an efficient Argsort #1145
- (might be more)
References
Metadata
Metadata
Assignees
Labels
No labels