|
From: Nico <nic...@li...> - 2006-02-10 20:46:22
|
> a = array([0,1,0,0]) > a[1:] |= a[:-1] > > gives the unexpected result [0 1 1 1] instead of [0 1 1 0] because > python performs the |= on the first cell, then on the second, and so on. > > I found two ways to get it right, with a copy: > b = a.copy() > a[1:] |= b[:-1] > > or working backward: > a[-1:1:-1] |= a[-2:0:-1] I finally noticed that a = array([0,1,0,0]) a[1:] |= a[:-1] | False also works, but I can't figure out why... -- Nico |