I have a python code where I need to count the number of ids in a given range of timestamps as :

for i in range(numbers):
   indices=numpy.argwhere((a[i] >= dataset[:,0])  & (a[i] <= dataset[:,1]))

Here, numbers is an integer indicating the length of the array (a) that has timestamps. dataset[:,0] and dataset[:,1] has starting and ending ranges for timestamps and I have to compute the unique ids for a timestamp from the dataset.

The issue is: it is taking approx 0.7 seconds for one loop iteration making it run for about 5 days based on the length of a.

Is there a way to optimize this code, for it to complete early.

  • 3
    \$\begingroup\$ Could you provide some sample data to play with? \$\endgroup\$ – Georgy Mar 12 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.