<font color="#000000"><br></font><br><div class="gmail_quote">On Sun, Mar 3, 2013 at 9:21 AM, Colin J. Williams <span dir="ltr"><<a href="mailto:cjw@ncf.ca" target="_blank">cjw@ncf.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On 02/03/2013 9:30 PM, gialloporpora wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Risposta al messaggio di Rick Johnson :<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
What are you trying to achieve exactly?<br>
</blockquote>
<br>
<br>
I would like to implement a class (vector) to works with vectors, for<br>
example using scalar multiplication:<br>
a*v = [a*v1, a*vn]<br>
and a dual class for dual vector (the only method that I'll change is<br>
the __str__ method to print it as colun.<br>
Sandro<br>
</blockquote></div>
Numpy facilitates this sort of thing more efficiently than using a List.<br></blockquote><div><br></div><div>As a couple people have already pointed out, numpy is the way to go for most scientific applications.  You have also been given good advice regarding 'properly' inheriting from 'list' by calling the list.__init__ function.</div>
<div><br></div><div>The only thing I'll add here is that you can inherit from array.array instead of list if you want a 'truly' numeric-vector without introducing numpy as a dependency.  The advantage array.array has over list in this instance is that it is type-restrictive for member data (it has to be pre-declared and throws TypeError if you try to pass it a bad variable type).</div>
<div><br></div><div>You can then proceed to override the __add__, __sub__, __mul__, and __div__ methods (and the in-place versions of these operators) to mimic vector operations.  (By default, __add__ appends the rhs to the lhs and returns a copy of that for array.array and list).</div>
<div><br></div><div>You can avoid all this work, however, and just use numpy.ndarray instead ;).</div><div><br></div><div>Good luck,<br>Jason</div></div>