[Numpy-discussion] [C++-sig] Overloading sqrt(5.5)*myvector

Robert Kern robert.kern@gmail....
Wed Dec 26 23:04:29 CST 2007

Bruce Sherwood wrote:
> Thanks for the suggestion. It hadn't occurred to me to try to override 
> numpy as you suggest. However, when I try the code shown below as the 
> start of a test of this scheme, I get the following error:
> Traceback (most recent call last):
>   File "C:\Documents and Settings\Bruce\My 
> Documents\0VPythonWork\vectors.py", line 24, in <module>
>     numpy.float64.__mul__ = new_mul
> TypeError: can't set attributes of built-in/extension type 'numpy.float64'
> I'm copying this to the numpy discussion list, as maybe someone there 
> will see where to go starting from your suggestion.

Like most (or all) builtin-types, the numpy float scalars do not permit
replacing their methods from Python.

I'm not familiar with vpython's vector. If you can make it "not look like an
ndarray", then you should be able to just implement __rmul__ on vector.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list