Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add dstack, vstack, and hstack #667

Closed
ngoldbaum opened this issue Jul 22, 2019 · 8 comments
Closed

Add dstack, vstack, and hstack #667

ngoldbaum opened this issue Jul 22, 2019 · 8 comments
Milestone

Comments

@ngoldbaum
Copy link

ngoldbaum commented Jul 22, 2019

In the vein of #75 which added stack, it would be really nice if there were a way to easily convert e.g. Vec<Array2<D>> into an Array3<D>. Current I'm doing something like this:

let imshape = data[0].shape()
let mut activation: Array3<f64> = Array3::zeros((n_batch, imshape[0], imshape[1]));
for (i, mm) in data.iter().enumerate() {
    activation.slice_mut(s![i, .., ..]).assign(&m);
}

It would be nice to not have to do this manually, it would also be clearer to people who are used to numpy (IMO).

I think this is equivalent to relaxing the restriction that axis in ndarray::stack has to be an existing axis.

@jturner314
Copy link
Member

What we call stack, NumPy calls concatenate, and we don't have an equivalent of NumPy's stack. I actually like NumPy's naming (concatenate along existing axis, stack along new axis) better than ndarray's.

Any thoughts on renaming the existing stack function/macro to concatenate or concat and adding a stack function that stacks along a new axis?

@LukeMathWalker
Copy link
Member

It sounds good to me - it would also help for issues like #650.

@bluss
Copy link
Member

bluss commented Sep 7, 2019

@jturner314 Sounds good

@andrei-papou
Copy link
Contributor

Seems like @bluss is a bit busy so could one of you guys @LukeMathWalker @jturner314 please take a look at the PR changes? Thanks a lot!

@TheButlah
Copy link

TheButlah commented Aug 17, 2020

New user of ndarray here - coming from python, I expected ndarray::stack to have the same semantics as np.stack, and it caught me off guard when it didnt. I was left scratching my head for a bit why the dimensions did not match up, until I took a closer look at the docs. I would also like to also put a vote in for changing the name to ndarray::concatenate.

Also, is there a ndarray alternative for np.stack now? Trying to find the function I should be using, but I'm not seeing one.

@ngoldbaum
Copy link
Author

No, that’s all in #735, which appears to have stalled.

@Luthaf
Copy link

Luthaf commented Mar 25, 2021

Looks like the name has been changed, but documentation in https://docs.rs/ndarray/0.14.0/ndarray/doc/ndarray_for_numpy_users/index.html still refer to stack! as the alternative for np.concatenate. Should it be updated?

@bluss
Copy link
Member

bluss commented Mar 25, 2021

That document issue should already be fixed in master, which is released as 0.15 soon.

The present feature request is closed - it was fixed already in 0.14.

@bluss bluss closed this as completed Mar 25, 2021
@bluss bluss added this to the 0.14.0 milestone Mar 25, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

7 participants