我知道,使用 package DataFrames,可以通过简单地做
julia> df = DataFrame();
julia> for i in 1:3
df[i] = [i, i+1, i*2]
end
julia> df
3x3 DataFrame
|-------|----|----|----|
| Row # | x1 | x2 | x3 |
| 1 | 1 | 2 | 3 |
| 2 | 2 | 3 | 4 |
| 3 | 2 | 4 | 6 |
Run Code Online (Sandbox Code Playgroud)
...但是有没有办法对空的做同样的事情Array{Int64,2}?
如果您知道最终数组中有多少行,则可以使用hcat:
# The number of lines of your final array
numrows = 3
# Create an empty array of the same type that you want, with 3 rows and 0 columns:
a = Array(Int, numrows, 0)
# Concatenate 3x1 arrays in your empty array:
for i in 1:numrows
b = [i, i+1, i*2] # Create the array you want to concatenate with a
a = hcat(a, b)
end
Run Code Online (Sandbox Code Playgroud)
请注意,这里您知道数组b具有类型为 的元素Int。因此,我们可以创建a具有相同类型元素的数组。