[Numpy-discussion] Optimization of loops

Stéfan van der Walt stefan@sun.ac...
Thu Oct 23 16:04:37 CDT 2008


2008/10/23 Charles R Harris <charlesr.harris@gmail.com>:
> In [4]: ind = [i for i,j in spikes]
> In [5]: tim = [j for i,j in spikes]

Just for interest's sake, 'zip' is an interesting function in that it
works both ways around:

In [26]: zip(*zip([1,2,3],[3,4,5]))
Out[26]: [(1, 2, 3), (3, 4, 5)]

So a person can do

In [27]: ind, tim = zip(*spikes)

Cheers
Stéfan


More information about the Numpy-discussion mailing list