python - How do I maximize efficiency with numpy arrays? -


I'm just getting numpy, and I'm impressed with my claims of C-like functionality. I wanted to see the differences between myself and these numerical lists, so I conducted a quick time test, without doing anything simple tasks without it. Nampi, as a candidate, removed the listed list regularly by an order of magnitude in the allocation and operation of mathematics. But this segment of code, similar in both tests, taken a little more than 2.5 seconds with 1/8 of each other and one with a regular list:

  file = open ('timing Number: 1000 == 0: file.write ("Multiple of 1000! \ R \ n") file.close ()  
for 'log', 'w')

Does anyone know why this can happen, and if there is any other syntax then I should use this kind of operation so that what ndarray can do better May Ab?

Thank you ...

Edit: To answer Wayne's comment ... I repeatedly gave him time to separate orders and every time much more Received similar results, so I suspect that this is another process. After Numpy Import, put

  start = time ()  
at the top of the file and after that I have the time after transceiver like
  print:  

code> A2 is a NumPy array, right? One possible reason may be that it is in NumPy for a long time (if the process of other processes is suggested as Wayne Werner), then you are running the array using the Python loop. In each stage of repetition, Python is supposed to get a value from the numerical array and convert it to a Python integer, which is not particularly fast operation.

When you are enabled, NumPy works better as an entity in your case to work on the whole array, one option (probably not even the fastest)

  file.write ("1000's multiple! \ R \ n" * (a2% 1000 == 0). ())  

Comparing the pure-Python equivalent Try it,

  file.write ("multiple of 1000! \ R \ n" * sum (filter (lambda eye: i% 1000 == 0, a2))) < / Code> 

or

  file.write ("1000 plus! \ R \ N" * amount (1 in i for 1 if i% 1000 == 0))  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -