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

Inconsistent array initialization with space and semicolon #20957

Closed
mprat opened this issue Mar 9, 2017 · 6 comments
Closed

Inconsistent array initialization with space and semicolon #20957

mprat opened this issue Mar 9, 2017 · 6 comments

Comments

@mprat
Copy link

mprat commented Mar 9, 2017

In Julia 0.5.0 array initialization is inconsistent when using spaces and semicolons.

julia> [1;2;3]
3-element Array{Int64,1}:
 1
 2
 3

Creates a 3-element rather than a 3x1 array. But, adding a space makes a 3x2 array:

julia> [[1;2;3] [4;5;6]]
3×2 Array{Int64,2}:
 1  4
 2  5
 3  6

Spaces add a second dimension and semicolons add rows, except for the [1;2;3] case.

julia> [1 2 3]
1×3 Array{Int64,2}:
 1  2  3

julia> [1 2 3]'
3×1 Array{Int64,2}:
 1
 2
 3

julia> [1 2 3; 4 5 6]
2×3 Array{Int64,2}:
 1  2  3
 4  5  6

Making initialization consistent so that a semicolon adds a row (i.e. [1;2;3] initialization creates a 3x1 array) makes array initialization more consistent.

@yuyichao
Copy link
Contributor

yuyichao commented Mar 9, 2017

The syntax are clearly documented and there isn't any inconsistency here.

There's no syntax for nx1 array literal.

@yuyichao yuyichao closed this as completed Mar 9, 2017
@yuyichao
Copy link
Contributor

yuyichao commented Mar 9, 2017

And dup of #17084

@StefanKarpinski
Copy link
Sponsor Member

What @yuyichao is getting at here is that this has been discussed a fair bit and while there doesn't seem to be a perfect set of rules for this, the current behavior seems to be a local optimum in terms of meshing well with higher dimensional arrays and working well for linear algebra. If you want to give more feedback on the design, please feel free to do so over at #17084 – which is still open since it's not at all implausible that some new design tweak here could improve upon what we have.

@mprat
Copy link
Author

mprat commented Mar 9, 2017

Ah, sorry! I thought I had done a keyword search about this but I guess I didn't find it - thanks! Will move over to the other thread.

@StefanKarpinski
Copy link
Sponsor Member

No worries – I can never find anything using GitHub search and I basically live on GitHub.

@alanedelman
Copy link
Contributor

sorry for the late chiming in:
"inconsistent" is not quite the right word, but it's fair to say that it can be confusing
until one sees how it works, and sometimes a good way to see how things work is to
hcat 2x2 matrices or other structures

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

4 participants