I have arrays with 2 dimensions. Elements in the arrays are only considered valid for certain values on the indices. For example, consider the arrays
A = round.(rand(10, 2) .* 100) A[1:3, 2] .= NaN B = round.(rand(10, 2) .* 100) B[1:3, 2] .= NaN
If it helps, you can think of the arrays as recording number of people, where the first index represents age groups, and the second index represents education level (HS and college). Younger individuals, say for indices 1 to 3, are too young to have a college degree, so those entries are illegal.
I have to perform operations on the arrays, say
prod. How can I skip the illegal indices for those operations? I can manually keep track of those indices as below
s = sum(A[a, e]*B[a, e] for a in 1:10, e in 1:2 if (e == 1) || ((e == 2) && (a > 3))) p = prod(A[a, e]*B[a, e] for a in 1:10, e in 1:2 if (e == 1) || ((e == 2) && (a > 3)))
Is there a better, less cumbersome, solution?