Skip to content

add numpy.partition like functionality #1497

Closed
@NewBornRustacean

Description

@NewBornRustacean

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

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions