Still trying to earn my numpy stripes: I want to perform an arithmetic operation on two numpy arrays, which is simple enough:
return 0.5 * np.sum(((array1 - array2) ** 2) / (array1 + array2))
Problem is, I need to be able to specify the condition that, if both arrays are element-wise 0 at the same element i
, don't perform the operation at all--would be great just to return 0 on this one--so as not to divide by 0.
However, I have no idea how to specify this condition without resorting to the dreaded nested for-loop. Thank you in advance for your assistance.
Edit: Would also be ideal not to have to resort to a pseudocount of +1.