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

Frank Horowitz frank@horow....
Fri Mar 19 02:55:06 CDT 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@horow.net






More information about the NumPy-Discussion mailing list