You need to iterate the array keeping the column-major layout in mind. map!
would do this for you. You may also loop over the array by yourself:
julia> using StatsBase
julia> blobs = rand(1:10, 10_000, 10_000);
julia> blobs_occ = countmap(vec(blobs))
Dict{Int64,Int64} with 10 entries:
7 => 9999281
4 => 10004145
9 => 9998303
10 => 10000867
2 => 10003930
3 => 10000831
5 => 10001701
8 => 9993679
6 => 9996181
1 => 10001082
julia> blob_counts = similar(blobs);
julia> function elcount!(blob_counts, blobs, blobs_occ)
for (ind, el) in enumerate(blobs)
blob_counts[ind] = blobs_occ[el]
end
return blob_counts
end
julia> @time elcount!(blob_counts, blobs, blobs_occ);
1.499894 seconds