On Fri, Nov 4, 2011 at 6:31 PM, Pauli Virtanen <p...@iki.fi> wrote: > 05.11.2011 00:14, T J kirjoitti: > [clip] > > a = 1 > > a += 2 > > a += IGNORE > > b = 1 + 2 + IGNORE > > > > I think having a == b is essential. If they can be different, that will > > only lead to confusion. On this point alone, does anyone think it is > > acceptable to have a != b? > > It seems to me that requiring this sort of a thing gives some > limitations on how array operations should behave. > > An acid test for proposed rules: given two arrays `a` and `b`, > > a = [1, 2, IGNORED(3), IGNORED(4)] > b = [10, IGNORED(20), 30, IGNORED(40)] > > (a) Are the following pieces of code equivalent: > > print unmask(a + b) > a += 42 > a += b > print unmask(a) > > and > > print unmask(b + a) > a += b > a += 42 > print unmask(a) > > (b) Are the following two statements equivalent (wrt. ignored values): > > a += b > a[:] = a + b > > For np.ma (a) is false whereas (b) is true. For arrays containing nans, > on the other hand (a) and (b) are both true (but of course, in this case > values cannot be unmasked). > > Is there a way to define operations so that (a) is true, while retaining > the desired other properties of arrays with ignored values? > > I thought that "PdC" satisfied (a) and (b). Let me show you what I thought they were. Perhaps I am not being consistent. If so, point out my mistake.
(A) You are making two comparisons. (A1) Does unmask(a+b) == unmask(b + a) ? Yes. They both equal: unmask([11, IGNORED(22), IGNORED(33), IGNORED(44)]) = [11, 22, 33, 44] (A2) Is 'a' the same after "a += 42; a += b" and "a += b; a += 42"? Yes. >>> a = [1, 2, IGNORED(3), IGNORED(4)] >>> b = [10, IGNORED(20), 30, IGNORED(40)] >>> a += 42; a [43, 44, IGNORED(45), IGNORED(46)] >>> a += b; a [53, IGNORED(64), IGNORED(75), IGNORED(86)] vs >>> a = [1, 2, IGNORED(3), IGNORED(4)] >>> b = [10, IGNORED(20), 30, IGNORED(40)] >>> a += b; a [11, IGNORED(22), IGNORED(33), IGNORED(44)] >>> a += 42; a [53, IGNORED(64), IGNORED(75), IGNORED(86)] For part (B), I thought we were in agreement that inplace assignment should be defined so that: a += b is equivalent to: tmp = a + b a = tmp If so, this definitely holds. Have I missed something? Probably. Please spell it out for me.
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion