[SciPy-Dev] how to multiply an instance of ndarray and an object?

Ilhan Polat ilhanpolat at gmail.com
Sat Mar 24 18:59:44 EDT 2018


Yes, you can write

__array_priority__ = 1000 # some number (bigger wins. But against what you
can never be sure)

or

__array_ufunc__ = None # NumPy 1.13+ only

somewhere in your class and NumPy will leave you alone because this
overrides its eagerness to handle the vectorization and ending up on object
data types.



On Sat, Mar 24, 2018 at 10:02 PM, Phillip Feldman <
phillip.m.feldman at gmail.com> wrote:

> I have a class called `Signal` that handles multiplication by an array on
> the right by overloading `__mul__`.  I tried to implement multiplication by
> an array on the left by overloading `__rmul__`, but wasn't able to make
> this work because NumPy thinks that it knows how to handle this, so my
> `__rmul__` method (below) is never called.  The result is an array having
> dtype `object`.  Is there a practical way to modify NumPy to solve this
> problem
>
> Phillip
>
>     def __rmul__(self, c):
>         S= self.copy()
>         S.phasors*= c
>         return S
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at python.org
> https://mail.python.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20180324/f8935414/attachment.html>


More information about the SciPy-Dev mailing list