[Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread Stas K
Can I get rid of the loop in this example? And what is the fastest way to get v in the example? ar = array([1,2,3]) for a in ar: for b in ar: v = a**2+b**2 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org

Re: [Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread josef . pktd
On Sat, Nov 7, 2009 at 1:51 PM, Stas K stanc...@gmail.com wrote: Can I get rid of the loop in this example? And what is the fastest way to get v in the example? ar = array([1,2,3]) for a in ar:    for b in ar:        v = a**2+b**2 ar[:,None]**2 + ar**2 array([[ 2, 5, 10], [ 5, 8,

Re: [Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread Alan G Isaac
On 11/7/2009 1:51 PM, Stas K wrote: Can I get rid of the loop in this example? And what is the fastest way to get v in the example? ar = array([1,2,3]) for a in ar: for b in ar: v = a**2+b**2 a2 = a*a np.add.outer(a2,a2) array([[ 2, 5, 10], [ 5, 8, 13],

Re: [Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread Stas K
Thank you, Josef It is exactly what I want: ar[:,None]**2 + ar**2 Do you know something about performance of this? In my real program ar have ~ 10k elements, and expression for v more complicated (it has some trigonometric functions) On 07.11.2009, at 21:57, josef.p...@gmail.com

Re: [Numpy-discussion] How to get rid of the loop?

2009-11-07 Thread Anne Archibald
2009/11/7 Stas K stanc...@gmail.com: Thank you, Josef It is exactly what I want: ar[:,None]**2 + ar**2 Do you know something about performance of this? In my real program ar  have ~ 10k elements, and expression for v more complicated (it has some trigonometric functions) The construction