[Numpy-discussion] speeding up getting a subset of a data array
Mon Aug 10 19:58:53 CDT 2009
On Mon, Aug 10, 2009 at 8:52 PM, Brennan
> 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...
> for index,pos in enumerate(subsetpointerlist):
> 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?
looks to me like
subsetarray = dataarray[subsetpointerlist]
or with type conversion
subsetarray = dataarray[subsetpointerlist].astype(float)
> NumPy-Discussion mailing list
More information about the NumPy-Discussion