matrix_1 = matrix_2 * matrix_3

Anton Vredegoor anton at
Mon Aug 26 18:21:12 CEST 2002

On Mon, 26 Aug 2002 16:05:30 +0200, holger krekel <pyth at>

>Do know how easy it is in python to redefine the star operator?
>>>> class a(str):
>...    def __mul__(self, other):
>...       return self.startswith(other) or other.startswith(self)
>>>> a1=a("hallo")
>>>> a2=a("hal")
>>>> a1*a2
>So you could inherit whatever matrix-class you like and (re)define
>the __mul__ operator to mean 'matrixmultiply'.  
>Ask back if you don't know what i am talking about :-)

Ok, I am asking :-)


>>> class myarray(Numeric.array):

	def test(self):

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in ?
    class myarray(Numeric.array):
TypeError: cannot create 'builtin_function_or_method' instances

More information about the Python-list mailing list