Hi all, I’m extending data arrays from 2 dimensions to 4 dimensions, and I want to make sure that the concatenation is doing what I think it’s doing. Previously, I used command loops like:
DatArr = Array{Float64,2}(undef, 1, 3)
DatArr = [[] [] []]
for i in 1:10
[x(i) y(i) z(i)] = {...big calculation...}
DatArr = vcat(DatArr, [x(i) y(i) z(i)])
end
But now, I have to do this same calculation not just once, but multiple times over a 2-dimensional matrix of input parameters. This is what I wrote at first, but I’m pretty sure it’s NOT right:
DatArr = Array{Float64,4}(undef, Nj, Nk, 1, 3)
for j in 1:Nj
for k in 1:Nk
DatArr[j,k] = [[] [] []]
end
end
(...much later...)
for i in 1:10
for j in 1:Nj
for k in 1:Nk
[x(i,j,k) y(i,j,k) z(i,j,k)] = {...big calculation...}
DatArr[j,k] = vcat(DatArr[j,k], [x(i,j,k) y(i,j,k) z(i,j,k)])
end
end
end
So… am I right in suspecting that this may be wrong, and NOT doing what I obviously am trying to do… the same concatenations as before, just doing it independently for each value of j
& k
? Can anyone give me suggestions on the CORRECT way to do these concatenations?
(FYI, due to heavy computational reasons, I cannot switch the order of the nested loops… the j
& k
loops MUST stay nested inside the for i in 1:10
loop.
Also, note that each new data expression like [x(i) y(i) z(i)]
is not really just a 1x3
array of floats, but is actually a shorthand way of me indicating an Nx3
array of floats, where N ~ few x 100.)
I’d be very grateful for any recommendations… thanks!