My program reads 4.2 million unsigned integers into an array (pulses) from a binary file using array.fromfile(). It then iterates over these integers and appends them into the appropriate list position (zones) based on a modulus operation. Currently the loop below takes ~2 seconds, but I'm hoping it can be done faster. I have spent hours trying different numpy approaches, some of which ended up being slower. I have clocked the various functions and this is definitely the bottleneck. Any ideas?
for idx,val in enumerate(pulses):
if (idx + 1)%nZones == 0 and idx != 0:
zones[zone].append(val)
zone = 0
else:
zones[zone].append(val)
zone += 1
Ex: There are 200 zones, pulse 1 goes to zone 1, pulse 2 to zone 2, etc until we get to 200th pulse, and pulse 201 goes to zone 1.