print('index   ' + str(timeit.timeit('A[C] += D[C]', setup, number=3)))
setup3 = setup + """ 
A = np.ma.array(np.ones((dim, dim)), mask = np.array(B - 1, dtype = np.bool))
"""
print('ma      ' + str(timeit.timeit('A += D', setup3, number=3)))
Numpy arrays with mixed mutable and immutable values