Slicing Python lists vs Slicing R vectors -
in r
can this
> = (10:19) > [1] 10 11 12 13 14 15 16 17 18 19 > b = c(4,7) > b [1] 4 7 > > a[b] [1] 13 16 > > a[-b] [1] 10 11 12 14 15 17 18 19
i suppose there equally elegant way of doing python (2.7) lists, haven't found yet. i'm particularly interested in a[-b]
bit. thoughts?
[edit] [10,11,12,13,14,15,16,17,18,19], b [4,7] (indices a)
you using list comprehensions
[n n, in enumerate(a) if not in b]
or using numpy:
x = np.arange(10, 20) y = [2, 7] x[y]
Comments
Post a Comment