[SciPy-User] Best method to pick-up every N-th sample of an array

Matthieu Rigal rigal at rapideye.de
Tue Aug 10 10:11:27 EDT 2010


Hi folks,

I could not find an appropriate function to pick-up every N-th value of an 
array into another one... for example :
[0,1,2,3,4,5] could return [0,2,4], for N = 2
Neither I could find help browsing the dev-lists

The functions numpy.choose and numpy.take may give correct results, but after 
having created the appropriate mask.. which may not be the best when you 
handle arrays containing hundred million of values, and I wouldn't be sure how 
to build it.

Therefore I wrote the following subfunction, but it is not very powerful:

def ReduceArray(x,y):
    x0=[]
    j=0
    for i in x:
        j=j+1
        if j==y:
            x0.append(i)
            j=0
    return numpy.array(x0)
    
Yes, using a simple Python list in between ... :-(((

So if you had some hints on which way to follow to have this computed quickly, 
on a flat or a ndarray, you will make someone happy :-)

Best regards,
Matthieu

PS : I apologize it this should have go to the numpy list, I was unsure...

RapidEye AG
Molkenmarkt 30
14776 Brandenburg an der Havel
Germany
 
Follow us on Twitter! www.twitter.com/rapideye_ag
 
Head Office/Sitz der Gesellschaft: Brandenburg an der Havel
Management Board/Vorstand: Wolfgang G. Biedermann
Chairman of Supervisory Board/Vorsitzender des Aufsichtsrates: 
Juergen Breitkopf 
Commercial Register/Handelsregister Potsdam HRB 17 796
Tax Number/Steuernummer: 048/100/00053
VAT-Ident-Number/Ust.-ID: DE 199331235
DIN EN ISO 9001 certified
 
*************************************************************************
Diese E-Mail enthaelt vertrauliche und/oder rechtlich geschuetzte
Informationen. Wenn Sie nicht der richtige Adressat sind oder diese
E-Mail irrtuemlich erhalten haben, informieren Sie bitte sofort den
Absender und vernichten Sie diese E-Mail. Das unerlaubte Kopieren sowie
die unbefugte Weitergabe dieser E-Mail ist nicht gestattet.
 
The information in this e-mail is intended for the named recipients
only. It may contain privileged and confidential information. If you
have received this communication in error, any use, copying or
dissemination of its contents is strictly prohibited. Please erase all
copies of the message along with any included attachments and notify
RapidEye AG or the sender immediately by telephone at the number
indicated on this page.



More information about the SciPy-User mailing list