Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

stack! doesn't work properly #1155

Closed
HyeokSuLee opened this issue Feb 15, 2022 · 3 comments
Closed

stack! doesn't work properly #1155

HyeokSuLee opened this issue Feb 15, 2022 · 3 comments

Comments

@HyeokSuLee
Copy link

HyeokSuLee commented Feb 15, 2022

example

  let a = array![[9., 7.], [5., 2.]];

  let b = array![[1., 9.], [5., 1.]];
  
  println!("a vstack b = \n{:?}\n", stack![Axis(0), a, b]);
  
  println!("a hstack b = \n{:?}\n", stack![Axis(1), a, b]);

should be

a vstack b = 
[[9.0, 7.0],
 [5.0, 2.0],
 [1.0, 9.0],
 [5.0, 1.0]], shape=[4, 2], strides=[2, 1], layout=C (0x1), const ndim=2

a hstack b = 
[[9.0, 7.0, 1.0, 9.0],
 [5.0, 2.0, 5.0, 1.0]], shape=[2, 4], strides=[4, 1], layout=C (0x1), const ndim=2

but it returns

a vstack b =
[[[9.0, 7.0],
  [5.0, 2.0]],

 [[1.0, 9.0],
  [5.0, 1.0]]], shape=[2, 2, 2], strides=[4, 2, 1], layout=Cc (0x5), const ndim=3

a hstack b =
[[[9.0, 7.0],
  [1.0, 9.0]],

 [[5.0, 2.0],
  [5.0, 1.0]]], shape=[2, 2, 2], strides=[2, 4, 1], layout=c (0x4), const ndim=3

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&code=%0D%0A%20%20use%20ndarray%3A%3Aprelude%3A%3A*%3B%0D%0A%20%20use%20ndarray%3A%3A%7BArray%2C%20Axis%2C%20stack%7D%3B%0D%0A%20%20%0D%0A%20%20fn%20main()%7B%0D%0A%20%20%20%20%20%20let%20a%20%3D%20array!%5B%5B9.%2C%207.%5D%2C%20%5B5.%2C%202.%5D%5D%3B%0D%0A%0D%0A%20%20%20%20%20%20let%20b%20%3D%20array!%5B%5B1.%2C%209.%5D%2C%20%5B5.%2C%201.%5D%5D%3B%0D%0A%20%20%20%20%20%20%0D%0A%20%20%20%20%20%20println!(%22a%20vstack%20b%20%3D%20%5Cn%7B%3A%3F%7D%5Cn%22%2C%20stack!%5BAxis(0)%2C%20a%2C%20b%5D)%3B%0D%0A%20%20%20%20%20%20%0D%0A%20%20%20%20%20%20println!(%22a%20hstack%20b%20%3D%20%5Cn%7B%3A%3F%7D%5Cn%22%2C%20stack!%5BAxis(1)%2C%20a%2C%20b%5D)%3B%0D%0A%20%20%7D

@jturner314
Copy link
Member

The concatenate! macro does what you're looking for. (Playground) concatenate! concatenates arrays along an existing axis; stack! stacks arrays along a new axis.

@HyeokSuLee
Copy link
Author

HyeokSuLee commented Feb 16, 2022

Great. But then, i think quick start tutorial need to be fixed.
/~https://github.com/rust-ndarray/ndarray/blob/master/README-quick-start.md

@jturner314
Copy link
Member

Oh, good catch. Thanks! I've created #1156 to fix the quick start tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants