gpt4 book ai didi

Julia 问题与结束,矩阵

转载 作者:行者123 更新时间:2023-12-04 15:39:11 30 4
gpt4 key购买 nike

当我在 julia 中输入这个错误跳转但我不知道为什么,它应该工作。/

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

julia> B = A[2:1:end; 2:1:end]
ERROR: syntax: missing last argument in "2:1:" range expression
Stacktrace:
[1] top-level scope at REPL[9]:0

formMA

最佳答案

索引多维数组的语法使用逗号 , 而不是分号 ; 作为维度之间的分隔符,参见 https://docs.julialang.org/en/v1/manual/arrays/#man-array-indexing-1 .因此你想做:

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

julia> B = A[2:1:end, 2:1:end]
3×3 Array{Int64,2}:
6 7 8
2 3 4
6 7 8

另请注意,您可以在范围规范中省略 1,因为步骤 1 是默认值:

julia> A[2:end, 2:end]
3×3 Array{Int64,2}:
6 7 8
2 3 4
6 7 8

关于Julia 问题与结束,矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58579344/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com