I have a binary file with alternating uint8 and uint64 data stamps.I read those in by using the following line:clicks = np.fromfile(filename, dtype=[('time','u8'),('channel','u2')])This works well and fast enough. Now i want to go though the array and set the time values to the time difference with respect to the last 'click' seen on channel 7 (the so called gate clicks). The array is sorted by time. In C I would do this with a simple for loop going over the array (and this works extremly fast). When I implement this in python i get a data rate of only 2 mb/s. The best solution i came up with looks like this:    ''' create an array with the indices of the channel-7 clicks '''    gate_clicks = clicks['channel']==7    gate_ind = np.array(range(len(gate_clicks)))    gate_ind = gate_ind[gate_clicks]    gate_ind_shift = np.delete(gate_ind,0,0)    ''' slice out the clicks between to gate clicks and set the time stamps '''    for start,end in zip(gate_ind,gate_ind_shift):        start_time = data[start]['time']        slice = data[start:end]         slice['time'] = slice['time']-start_time        data[start:end] = sliceThis gives a data rate of about 4.
Reading binary data from a file
python;performance