[Numpy-discussion] speeding up getting a subset of a data array

Brennan Williams brennan.williams@visualreservoir....
Mon Aug 10 19:52:54 CDT 2009


Hi

No doubt asked many times before so apologies....

I'm pulling a subset array out of a data array where I have a list of 
the indices I want (could be an array rather than a list actually - I 
have it in both).

Potentially the number of points and the number of times I do this can 
get very large so any saving in time is good.

So, paraphrasing what I've currently got.... say I have...

subsetpointerlist=[0,1,2,5,8,15,25...]
subsetsize=len(subsetpointerlist)
subsetarray=zeros(subsetsize,dtype=float)
for index,pos in enumerate(subsetpointerlist):
  subsetarray[index]=dataarray[pos]

How do I speed this up in numpy, i.e. by removing the for loop?

Do I set up some sort of a subsetpointerarray as a mask and then somehow 
apply that to dataarray to get the values into subsetarray?

Thanks

Brennan






More information about the NumPy-Discussion mailing list