[Numpy-discussion] evaluating a function in a matrix element???

Frank Horowitz frank at horow.net
Fri Mar 19 03:55:06 EDT 2010


> >>>
>  class X:
> 
> ...     def __mul__(self, other):
> ...             return numpy.random.random() * other
> ...     def __rmul__(self, other):
> ...             return other * numpy.random.random()


Thanks for that Friedrich! 

I had forgotten about __mul__,  __rmul__,  __float__ et al. I think that using a class method instead of a function and overriding those __*__ methods is the cleaner way to do the task I need. 

Cheers,
	Frank Horowitz
	frank at horow.net







More information about the NumPy-Discussion mailing list