overloading __mul__
zunbeltz
zunlatex at hotmail.com
Wed Mar 12 10:03:31 CET 2003
Hello
I'm defining 2 clases. They are like a matrix anda a vector. The
matrix
is a square one using list insie list [[1,2],[3,4]] and the vector is
a list [5,6].
I want to be able to write things like that
2*matrix
matrix * 2
2*vector
vector *2
but also
matrix*vector
vector*matrix
How can i overload __mul__ for matrix in two ways depending if the
other elemetn is a number or a vecotr? and in wich class have i to
overload __mul__ to get vector * matrix and matrix * vector; in the
vector class? in the matrix class? in both?
thanks in advance
Zunbeltz
More information about the Python-list
mailing list