我想创建一个数组,如下所示
1、2、1、3、2、1、4、3、2、1
我使用以下代码,这应该是正确的,但我没有得到我想要的结果。
x = 0
for i in 1:4
for z in i:1
x = x + 1
index[x] = z
end
end谢谢您抽时间见我。
发布于 2018-06-26 12:23:49
我将使用以下一行代码:
index = [ n for m in 1:4 for n in m:-1:1 ]如果出于某种原因,您实际上需要预先分配index,您还可以更详细地编写循环,如下所示:
m = 4
index = ones(Int, sum(1:m))
c = 1
for m in 1:4
for n in m:-1:1
index[c] = n
c += 1
end
endhttps://stackoverflow.com/questions/51034699
复制相似问题