I am interested in the best / fastest way to do operations with an array (dot, outer, add, etc.), ignoring some values ββin the array. I am mainly interested in cases where some (perhaps 50% -30%) values ββare ignored and actually equal to zero with moderately large arrays, possibly from 100,000 to 1,000,000 elements. There are a number of solutions that I can think of, but none of them, apparently, can benefit from the possible advantages that allow to ignore some values. For instance:
import numpy as np
A = np.ones((dim, dim))
B = np.random.random_integers(0, 1, (dim, dim))
C = np.array(B, dtype = np.bool)
D = np.random.random((dim, dim))
A += B * D
A[C] += D[C]
A = np.ma.array(np.ones((dim, dim)), mask = np.array(B - 1, dtype = np.bool))
A += D
edit1:
, . , , . , , A, B, (1 = , 0 = ) nump C, - A = A + B.multiply(C) A B .