Skip to content

stack! doesn't work properly #1155

Closed
Closed

Description

@HyeokSuLee

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

Activity

  1. jturner314 commented on Feb 16, 2022

    @jturner314
    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.

  2. HyeokSuLee commented on Feb 16, 2022

    @HyeokSuLee
    Author

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

  3. jturner314 commented on Feb 17, 2022

    @jturner314
    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

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