Reputation: 123
So say a=[[1 2];[3 4];[5 6]] and x is [1,2,1] how would I extract the vector [1,4,5]; that is, the index-x element of each row.
Upvotes: 1
Views: 571
Reputation: 42214
You can use broadcasting. Use Ref(a)
to avoid broadcasting over a
:
julia> getindex.(Ref(a),1:length(x),x)
3-element Array{Int64,1}:
1
4
5
Upvotes: 2