Skip to content

Array.squeeze() #1395

@barakugav

Description

@barakugav

Is there a reason why squeeze() is not provided by the library? Its very useful.
I think it can be implemented fairly easily:

pub trait Squeeze {
    fn squeeze(self) -> Self;
}
impl<S> Squeeze for ArrayBase<S, IxDyn>
where
    S: RawData,
{
    fn squeeze(self) -> Self {
        let mut out = self;
        for axis in (0..out.shape().len()).rev() {
            if out.shape()[axis] == 1 && out.shape().len() > 1 {
                out = out.remove_axis(Axis(axis));
            }
        }
        out
    }
}

Is there already such a function with a different name and i missed it?
Is there a problem with the implementation above?
Thanks for the support, this library is amazing!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions