[Numpy-discussion] puzzle: generate index with many ranges

Raik Gruenberg raik.gruenberg@crg...
Fri Jan 30 12:53:57 CST 2009


Pierre GM wrote:
> On Jan 30, 2009, at 1:11 PM, Raik Gruenberg wrote:
> 
>> Mhm, I got this far. But how do I get from here to a single index  
>> array
>>
>> [ 4, 5, 6, ... 10, 0, 1, 2, 3, 11, 12, 13, 14 ] ?
> 
> np.concatenate([np.arange(aa,bb) for (aa,bb) in zip(a,b)])

exactly! Now, the question was, is there a way to do this only using numpy 
functions (sum, repeat, ...), that means without any python "for" loop?

Sorry about being so insistent on this one but, in my experience, eliminating 
those for loops makes a huge difference in terms of speed. The zip is probably 
also quite costly on a very large data set.

Thanks!
Raik

> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> 
> 

-- 
________________________________

Dr. Raik Gruenberg
http://www.raiks.de/contact.html
________________________________


More information about the Numpy-discussion mailing list