Slice array of arrays in Julia -
Slice array of arrays in Julia -
in julia, have array of arrays, say:
arr = array(array{float64,1},3) = 1:3 arr[i] = [i,-i] end now:
arr[:][1] 2-element array{float64,1}: 1.0 -1.0 and
arr[1][:] 2-element array{float64,1}: 1.0 -1.0 it seems way first 'column' comprehension
pluses = [arr[i][1] i=1:length(arr)] 3-element array{any,1}: 1.0 2.0 3.0 is indeed way? lose in speed running loop instead of 'vectorized' version, or not matter in julia due different compiler?
this cannot done [] indexing. each [] operation independent operation (calling getindex). have tried "slicing" nested arrays calling arr[:][1]. there 2 independent operations here: first, (arr[:]), , (arr[:])[1]. in case arr[:] == arr! arr[1][:] — you're getting elements of first vector. that's why 2 returning same thing.
your comprehension solution. unlike old* versions of matlab, julia's jit makes loops faster vectorized alternatives. takes getting used if you're coming matlab or python. allows traverse these kinds of complicated structures in efficient manner.
with regards comment, reason used vector of vectors in case instead of adding columns multidimensional array vectors can grow. can re-create vector of vectors 2 dimensional array calling hcat(arr...), if vectors big (millions of elements) re-create slow.
*(recent versions of matlab have jit, well, can create some loops faster vectorization, too, when kicks in unpredictable. loops these days faster arrayfun/cellfun custom functions, in experience).
arrays julia-lang
Comments
Post a Comment