嵌套追加到Julia中的数组 [英] Nested append to an Array in Julia
本文介绍了嵌套追加到Julia中的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在python中,它类似于:
In python this would be something like:
Z = []
z = 1
Z.append([z])
例如,将创建Z= [[1]]
的
.但是在Julia中,我似乎无法重新创建相同的结构.我可以追加,但不知道如何嵌套.这是我正在做的总结:
which would create Z= [[1]]
for example. But in Julia, I cannot seem to re-create the same structure. I can append, but don't know how to nest. Here is what I am doing in summary:
Z = []
# loop
z = dotProduct(X, yArray) # single digit
append!(Z, z)
然后生成以下内容
0Any[0, 0, 0, 0, 1, 1, 1, 1]
我想要的地方:
[[0], [0], [0], [0], [1], [1], [1], [1]]
在朱莉娅中做到这一点的最佳方法是什么?
What is the best way to do this in Julia?
推荐答案
我发现完成这项工作的唯一方法是:
The only way I found to make this work was the following:
Z = Array{Int64,1}[]
push!(Z, [1])
push!(Z, [2])
print(Z)
给予
Array{Int64,1}[[1], [2]]
不太优雅,但是如果没有Array关键字,我似乎无法正常工作.
Not very elegant, but I cannot seem to get this working without the Array keyword.
这篇关于嵌套追加到Julia中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文