def update(self, arr, mask=None):
if mask is not None:<EOL><INDENT>refI = np.logical_and(mask, self.n == <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>refI = self.n == <NUM_LIT:0><EOL><DEDENT>if refI.any():<EOL><INDENT>self.avg[refI] = arr[refI]<EOL><DEDENT>self.n[mask] += <NUM_LIT:1><EOL>if mask is not None:<EOL><INDENT>i = mask  <EOL><DEDENT>else:<EOL><INDENT>i = self.n > <NUM_LIT:0><EOL><DEDENT>xn = arr[i]<EOL>x0 = self.avg[i]<EOL>n = self.n[i]<EOL>new_Avg = self.avg[i] + ((xn - x0) / n)<EOL>if self.var is not None:<EOL><INDENT>t = (xn - new_Avg + x0 - self.avg[i]) * (xn - x0) / (n - <NUM_LIT:1>)<EOL>t = np.nan_to_num(t)<EOL>self.var[i] += t<EOL><DEDENT>self.avg[i] = new_Avg<EOL>
update moving average (and variance) with new ndarray
(of the same shape as the init array) and an optional mask