在朱莉娅(Julia)中,如何初始化一个二维数组(一个矩阵),其中每个元素是列向量的?
使用Julia版本1.7.3,我的理解是,以下初始化矩阵
是9×9矩阵每个元素的元素不确定……
matrix = Array{Char}( undef, 9, 9 )
println( matrix )
display( matrix )
println( )
println( typeof(matrix) )
println( size(matrix) )
另外,我知道expression for c for c for c for C ='1':'9']
评估9个字符的列向量(类型vector {char}
)。
如何将上述组合以创建一个9×9矩阵,每个矩阵的81个元素是列vector ['1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9']
? (我的期望是,我计划编写的程序中将修改每个列向量元素。) 到目前为止,我最好的猜测是……
matrix = Array{Vector{Char}}( [ c for c = '1' : '9' ], 9, 9 )
试图这样做会导致…
ERROR: LoadError: MethodError: no method matching (Array{Vector{Char}})(::Vector{Char}, ::Int64, ::Int64)
Using Julia version 1.7.3, my understanding is that the following initializes matrix
to be a 9 × 9 matrix each of whose elements is undefined …
matrix = Array{Char}( undef, 9, 9 )
println( matrix )
display( matrix )
println( )
println( typeof(matrix) )
println( size(matrix) )
Also, I understand that the expression [ c for c = '1' : '9' ]
evaluates to a column vector of 9 characters (type Vector{Char}
).
How does one combine the above to create a 9 × 9 matrix each of whose 81 elements is the column vector [ '1'; '2'; '3'; '4'; '5'; '6'; '7'; '8'; '9' ]
? (My expectation is that each column vector element will be modified in the program I plan to write.) My best guess so far is …
matrix = Array{Vector{Char}}( [ c for c = '1' : '9' ], 9, 9 )
Attempting to do so results in …
ERROR: LoadError: MethodError: no method matching (Array{Vector{Char}})(::Vector{Char}, ::Int64, ::Int64)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,
数组
s可以是多维的(超过2个),因此也是一个3维数组。也只需要一个小更改:[C for C ='1':'9',_ in 1:9,_ in 1:9]
Note that
Array
s can be multidimensional (beyond 2), so a 3-dimensional array is also an option. Only requires a small change too:[ c for c = '1' : '9', _ in 1:9, _ in 1:9]
这是你想要的吗?
或者
Is this what you want?
or