[Numpy-discussion] a 'for' loop within another 'for' loop?

Hee-Seng Kye kyeser at earthlink.net
Tue Jul 13 23:30:13 EDT 2004


Thank you so much.  It works beautifully!

On Jul 14, 2004, at 1:01 AM, Warren Focke wrote:

> l = Numeric.add.outer(r, r).flat
> oughta do the trick.  Should work for numarray, too.
>
> On Tue, 13 Jul 2004, Hee-Seng Kye wrote:
>
>> 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!
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>





More information about the NumPy-Discussion mailing list