ndarray
ndarray copied to clipboard
Array.squeeze()
trafficstars
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!