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

The array! macro's documentation should clarify that if we attempt to create arrays with more than 3 dimensions they are ignored #1252

Open
nbro opened this issue Dec 28, 2022 · 0 comments

Comments

@nbro
Copy link
Contributor

nbro commented Dec 28, 2022

The documentation says

Create an Array with one, two or three dimensions.

This is fine.

However, I wonder if the following code should be able to run silently (not even a warning).

use ndarray::array;

fn main() {
    let a = array![
        [
                [[[2, 2]]], 
                [[[3, 1]]], 
                [[[5, 3]]], 
                [[[2, 2]]]
        ]
        ];
    println!("An int array with shape {:?}: {:?}", a.shape(), a.ndim()); // Shape is [1, 4, 1]
}

Basically, what's happening is that some dimensions or parentheses are automatically ignored. I think this should at least be documented or maybe the macro should fail in those cases? I am happy to contribute to the documentation, if you think that's the way to go in this case. I am also opening this issue because, if we attempt to create a similar thing in numpy with e.g. the following code

import numpy as np

a = np.array(
        [
                [[[2, 2]]], 
                [[[3, 1]]], 
                [[[5, 3]]], 
                [[[2, 2]]]
        ]
        )

print(a.shape)

We get a different shape: (4, 1, 1, 2).

Btw, I suppose there's no macro that allows us to create arrays from literals with more than 3 dimensions. Is that correct? Is there any reason why the macro only supports up to 3 dimensions? In machine learning, for example, it it's not rare to have multi-dimensional arrays with more than 3 dimensions, so I think that supporting the creation of arrays from literals with more than 3 dimensions would not be a bad idea.

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

1 participant