[Numpy-discussion] help speed up

Ferenc.Pintye at eu.decoma.com Ferenc.Pintye at eu.decoma.com
Wed Mar 15 04:10:05 CST 2006





Hi ,

why is this little algorithm so too slow (10x) in Numpy  than in numarray ?
(i think, the if-elif-else procedure runs with numpy array indicies so
slow...)

#
import time
import os
#
#
#####from numarray.random_array import *
from numpy import *
#
#####vector = random(50000)
vector = rand(50000)
#
length = len(vector)
out_1 = [0,0,0]
#
#
start = time.time()
#
#
i = 0
while i < length-3:
                  #
                  #
                  x1 = vector[i]
                  x2 = vector[i+1]
                  x3 = vector[i+2]
                  x4 = vector[i+3]
                  #
                  if x2>x3>=x1 and x4>=x2:
                        out_1[0] = x3
                        out_1[1] = x2
                        out_1[2] = 1
                  #
                  elif x1>=x3>x2 and x2>=x4:
                        out_1[0] = x2
                        out_1[1] = x3
                        out_1[2] = 1
                  else:
                        out_1[0] = 0
                        out_1[1] = 0
                        out_1[2] = 0
                  #
                  #
                  if out_1[2] == 1:
                        i += 1
                  i += 1
#
#
end = time.time()
elapsed = end-start
print "Running time : %.3f seconds" % (elapsed)
#
#







More information about the Numpy-discussion mailing list