<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr; font-family: Tahoma; color: rgb(0, 0, 0); font-size: 13px;">
<div style="">Hi,<br>
<br>
There are some discussions on the speed of numpy compared to Numeric in this list, however I have a topic<br>
I don't understand in detail, maybe someone can enlighten me...<br>
I use python 2.6 on a SuSE installation and test this:<br>
</div>
<div><br>
#Python 2.6 (r26:66714, Mar 30 2010, 00:29:28)<br>
#[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2<br>
#Type "help", "copyright", "credits" or "license" for more information.<br>
<br>
import timeit<br>
<br>
#creation of arrays and tuples (timeit number=1000000 by default)<br>
<br>
timeit.Timer('a((1.,2.,3.))','from numpy import array as a').timeit()<br>
#8.2061841487884521<br>
timeit.Timer('a((1.,2.,3.))','from Numeric import array as a').timeit()<br>
#9.6958281993865967<br>
timeit.Timer('a((1.,2.,3.))','a=tuple').timeit()<br>
#0.13814711570739746<br>
<br>
#Result: tuples - of course - are much faster than arrays and numpy is a bit faster in creating arrays than Numeric<br>
<br>
#working with arrays<br>
<br>
timeit.Timer('d=x1-x2;sum(d*d)','from Numeric import array as a; x1=a((1.,2.,3.));x2=a((2.,4.,6.))').timeit()<br>
#3.263314962387085<br>
timeit.Timer('d=x1-x2;sum(d*d)','from numpy import array as a; x1=a((1.,2.,3.));x2=a((2.,4.,6.))').timeit()<br>
#9.7236979007720947<br>
<br>
#Result: Numeric is three times faster than numpy! Why?<br>
<br>
#working with components:<br>
<br>
timeit.Timer('d0=x1[0]-x2[0];d1=x1[1]-x2[1];d2=x1[2]-x2[2];d0*d0+d1*d1+d2*d2','a=tuple; x1=a((1.,2.,3.));x2=a((2.,4.,6.))').timeit()<br>
#0.64785194396972656<br>
timeit.Timer('d0=x1[0]-x2[0];d1=x1[1]-x2[1];d2=x1[2]-x2[2];d0*d0+d1*d1+d2*d2','from numpy import array as a; x1=a((1.,2.,3.));x2=a((2.,4.,6.))').timeit()<br>
#3.4181499481201172<br>
timeit.Timer('d0=x1[0]-x2[0];d1=x1[1]-x2[1];d2=x1[2]-x2[2];d0*d0+d1*d1+d2*d2','from Numeric import array as a; x1=a((1.,2.,3.));x2=a((2.,4.,6.))').timeit()<br>
#0.97426199913024902<br>
<br>
Result: tuples are again the fastest variant, Numeric is faster than numpy and both are faster than the variant above using the high-level functions!<br>
Why?<br>
<br>
For various reasons I need to use numpy in the future where I used Numeric before.<br>
Is there any better solution in numpy I missed?<br>
<br>
Kind regards and thanks in advance<br>
<br>
Thomas<br>
<br>
<div style="font-family: Tahoma; font-size: 13px;">
<div style="font-family: Tahoma; font-size: 13px;"></div>
</div>
</div>
</div>
<P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">If you are not one of the named recipients or have received this email in error, </P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(i) you should not read, disclose, or copy it,</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(ii) please notify sender of your receipt by reply email and delete this email and all attachments,</P> <P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">(iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email.</P><P style="FONT-STYLE: italic; MARGIN: 0px 0px 0px 35.4pt; FONT-FAMILY: Arial, Helvetica, sans-serif; COLOR: #1f497d; FONT-SIZE: 9pt"><P style="FONT-SIZE: 9pt; MARGIN: 0px 0px 0px 35.4pt; COLOR: #1f497d; FONT-STYLE: italic; FONT-FAMILY: Arial, Helvetica, sans-serif">For other languages, <A href="http://www.3ds.com/terms/email-disclaimer">Click Here</A></P></body>
</html>