I’m building an array of cube centers for a 3-D cartesion grid, something like (ignore for the moment, for simplicity, that the cube centers are actually located at an offset of dx/2, dy/2, dz/2).
for i=1:nx
for j=1:ny
for k = 1:nz
a[i,j,k,1] = i*dx # i=1:nx
a[i,j,k,2] = j*dy # j=1:ny
a[i,j,k,3] = k*dz # k=1:nz
end
end
end
realizing that the sequences are repeated, i.e. you can do
xs = dx * range(0,nx-1,nx)
for j=1:ny
for k=1:nz
a[:,j,k,1] .= xs
end
end
and then you need two more loops for the 2nd and 3rd indexes.
Works great, but it’s not clever enough . It seems like this is amenable to a one-liner hack. I am seeking that one-liner hack, just for fun. Even the brute force 3-loop calculation of the values for a 64M array takes LESS than 2 seconds, so not worried about efficiency at all.
I’m just figuring some julia hacker out there can give me a valuable lesson in broadcasting