julia中的矩阵给出了列输出

时间:2015-05-08 19:07:50

标签: julia

也许我错过了什么,但考虑下一个矩阵:

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] ***

朱莉娅提供的输出是错的,对吧?

1 个答案:

答案 0 :(得分:9)

这种表示法意味着您要通过构建数组,而不是行:

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      

所以你得到了你认为自己的阵列的转置。