[SciPy-user] getting rid of for loops...

Emanuele Zattin emanuelez at gmail.com
Thu Aug 2 05:05:02 EDT 2007


Hello!

say A is an array and N is an integer. Is there any smart (read fast!)
way to obtain an array C that contains each row of A repeated N times?

What i'm trying to do is to optimize something that looks like this:

close_enough = []
tollerance = array([10, 15, 5, 8, 6])
for row_i in data1:
   for row_j in data2:
      if less(absolute(row_i - row_j), tollerance).all:
         close_enough.append([row_i, row_j])

i was thinking that using matrices like the ones described above i
might be able to get rid of the for loops and (maybe) speed up the
code (now it takes something like one minute).

-- 
Emanuele Zattin
---------------------------------------------------
-I don't have to know an answer. I don't feel frightened by not
knowing things; by being lost in a mysterious universe without any
purpose — which is the way it really is, as far as I can tell,
possibly. It doesn't frighten me.- Richard Feynman



More information about the SciPy-User mailing list