Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Include a specific error, tasPython/Numpy have I already written the swiftest code for large array?

python numpy optimization

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 justforkicks1


    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 12 December 2017 - 11:16 AM


I would like to get my script total execution time down from 4 minutes to less than 30 secs. I have a large 1d array (3000000+) of distances with many duplicate distances. I am trying to write the swiftest function that returns all distances that appear n times in the array. I have written a function in numpy but there is a bottleneck at one line in the code. Swift performance is an issue because the calculations are done in a for loop for 2400 different large distance arrays. 

   import numpy as np
    for t in range(0, 2400):
     a=np.random.randint(1000000000, 5000000000, 3000000)
     c=np.where(b == 3)[0] #SLOW STATEMENT/BOTTLENECK
     return c


Given a 1d array of distances [2000000000,3005670000,2000000000,12345667,4000789000,12345687,12345667,2000000000,12345667]

I would expect back an array of [2000000000,12345667] when queried to return an array of all distances that appear 3 times in the main array.



What should I do?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download