user2820579
user2820579

Reputation: 3451

Matrix in julia gives column output

Perhaps I am missing something, but consider the next matrix:

julia> a = [[0,1,1,1,1,0,0,0,1] [1,0,1,0,1,1,1,0,0] [1,1,0,0,0,0,1,1,1] 
[1,0,0,0,1,0,0,0,0] [1,1,0,1,0,0,0,0,0] [0,1,0,0,0,0,1,0,0]
[0,1,1,0,0,0,0,0,1] [0,0,1,0,0,0,0,0,1] [1,0,1,0,0,0,0,1,0]]

9x9 Array{Int64,2}:
 0  1  1  1  1  0  0  0  1 # <-- [0,1,1,1,1,0,0,0,1]
 1  0  1  0  1  1  1  0  0 # <-- [1,0,1,0,1,1,1,0,0]
 1  1  0  0  0  0  1  1  1 # <-- [1,1,0,0,0,0,1,1,1]
 1  0  0  0  1  0  0  0  0 # <-- [1,0,0,0,1,0,0,0,0]
 1  1  0  1  0  0  0  0  0 # <-- [1,1,0,1,0,0,0,0,0]
 0  1  0  0  0  0  0  0  0 # <-- [0,1,0,0,0,0,1,0,0] ***
 0  1  1  0  0  1  0  0  0 # <-- [0,1,1,0,0,0,0,0,1] ***
 0  0  1  0  0  0  0  0  1 # <-- [0,0,1,0,0,0,0,0,1]
 1  0  1  0  0  0  1  1  0 # <-- [1,0,1,0,0,0,0,1,0] ***

The output provided by julia is wrong, right?

Upvotes: 0

Views: 102

Answers (1)

DSM
DSM

Reputation: 352979

That notation means that you're building up an array by columns, not rows:

julia> a = [[1,2] [3,4]]                                                                                                                                            
2x2 Array{Int64,2}:                                                                                                                                                 
 1  3                                                                                                                                                               
 2  4                                                                                                                                                               

julia> a = [[1 2];[3 4]]                                                                                                                                            
2x2 Array{Int64,2}:                                                                                                                                                 
 1  2                                                                                                                                                               
 3  4      

And so you're getting the transpose of the array you think you are.

Upvotes: 9

Related Questions