[Numpy-discussion] Fast decrementation of indices
Alexander Belopolsky
ndarray at mac.com
Sun Feb 2 17:43:39 EST 2014
On Sun, Feb 2, 2014 at 2:58 PM, Mads Ipsen <mads.ipsen at gmail.com> wrote:
> Since atoms [1,2,3,7,8] have been
> deleted, the remaining atoms with indices larger than the deleted atoms
> must be decremented.
>
Let
>>> x
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
and
>>> i = [1, 0, 2]
Create a shape of x matrix with 1's at (k, i[k]) and zeros elsewhere
>>> b = zeros_like(x)
>>> b.put(i + arange(3)*4 + 1, 1) # there must be a simpler way
>>> x - b.cumsum(1)
array([[ 0, 1, 1, 2],
[ 4, 4, 5, 6],
[ 8, 9, 10, 10]])
seems to be the result you want.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140202/e0294896/attachment.html>
More information about the NumPy-Discussion
mailing list