I have an array of 1000 points, an Array{Array{Float64,1}} with length 1000. To separate the points into vectors of coordinates for each dimension, my Python instinct is to unpack the zipped points. For example, in Julia,
points = [rand(2) for i=1:1000]
x, y = zip(points...)
but this takes forever. I have to close the terminal window to kill it. Am I doing something wrong?
Ok, that works quickly, thank you. So, for an n-dimensional point the line would be X = [getindex.(points, Ref(n)) for n in 1:length(points[1])]
or something similar?
The problem here is that the ... operator in zip(points...) means you are calling the zip function with 1000 arguments (one for each point). That’s not something the Julia compiler is well-optimized for because it’s not something that people usually want. It takes forever because the compiler is (unhelpfully) trying to generate a specialized implementation for zipping 1000 different arguments.