[Numpy-discussion] a 'for' loop within another 'for' loop?
Hee-Seng Kye
kyeser at earthlink.net
Tue Jul 13 19:35:39 EDT 2004
Hi. I wrote a program to calculate sums of every possible combinations
of two indices of a list. The main body of the program looks something
like this:
r = [0,2,5,6,8]
l = []
for x in range(0, len(r)):
for y in range(0, len(r)):
k = r[x]+r[y]
l.append(k)
print l
1. I've heard that it's not a good idea to have a 'for' loop within
another 'for' loop, and I was wondering if there is a more efficient
way to do this.
2. Does anyone know if there is a built-in function or module that
would do the above task in NumPy or Numarray (or even in Python)?
I would really appreciate it if anyone could let me know.
Thanks for your help!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 715 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20040713/94401aa2/attachment.bin>
More information about the NumPy-Discussion
mailing list