I want to assign be able to assign values to different column value in each row. In the above example, I want to select 1st element from row 1, 2nd element from row 2 and 1st element from row 3 and assign different values to each of these element. In python, I could do this using l[1,2,3],[1,2,1]]=[7,8,9] where l is a nd numpy array.
Is there an efficient way of doing this other than using loops?
function non_scalar_indexing(arr::Array{Float32,2}, idx1::Array{Int64,1}, idx2::Array{Int64,1},value::Array{Float32,1})
index=0
for idx in zip(idx1,idx2)
arr[idx[0],idx[1]]=value[index];
index+=1;
end
return arr
end
I also would like to be able to handle case where arr is Array{Float32,3} and value is Array{Float32,2}.
Loops in Julia aren’t bad! In fact, they’ll often be faster than trying to jam everything onto one line. Note that writing everything on a single line does not “parallelize” it.
I’ve often referred to the kind of indexing you’re after here as “pointwise”, and one way of compactly representing it is with CartesianIndex: