Hi all, I'm new in Julia and I'm doing refactoring. I have the following function:
function mapeBase_v1(A::Vector{Float64}, F::Vector{Float64}) s = 0.0 count = 0 for i in 1:length(A) if(A[i] != 0.0) s += abs( (A[i] - F[i]) / A[i]) count += 1 end end s, count end I'm looking for a simpler variant which is as follows: function mapeBase_v2(A::Vector{Float64}, F::Vector{Float64}) # A - actual target values # F - forecasts (model estimations) s = sumabs((x - y) / x for (x, y) in zip(A, F) if x != 0) # Generator count = length(A) # ??? s, countend However with this variant can not determine the number of non-zero elements. I found option with length(A[A .!= 0.0]), but it has a large allocation. Please, someone knows a solution with generator, or variant v1 is very good choice? Thanks in advance, Martin