You mean:
def mydot(A,B):
    if isinstance(A, np.ndarray) and isinstance(B, np.ndarray):
        return np.dot(A, B)
    else:
        # mycode
?
Maybe you are right. Since I can't overload `np.dot`, maybe the neater way 
is to write a higher level function and then delegate the work by 
inspecting the type.


On Friday, October 7, 2016 at 7:56:59 PM UTC+2, Gabriel Gellner wrote:
>
> Any reason to not just use a function? (like np.dot etc)
>
> My understanding is that in python '*' means elementwise multiplication, 
> so even if you could monkeypatch numpys __mul__ method to do the right 
> thing wouldn't you be changing the semantics?
>
> Gabriel
>
> On Friday, October 7, 2016 at 3:51:11 AM UTC-6, Sisyphuss wrote:
>
>> In Julia, we can do multiple dispatch for operators, that is the 
>> interpreter can identify:
>> float + integer
>> integer + integer
>> integer + float
>> float + float
>> as well as *user-defined* data structure.
>>
>> Recently, I am working on Python (I have no choice because Spark hasn't 
>> yet a Julia binding). I intended to do the same thing -- multiplication -- 
>> between a Numpy matrix and self-defined Low-rank matrix. Of course, I 
>> defined the `__rmul__ ` method for Low-rank matrix. However, it seems to me 
>> that the Numpy matrix intercepts the `*` operator as its `__mul__` method, 
>> which expects the argument on the right side of `*` to be a scalar.
>>
>> I would like to know if there is anyway around?
>>
>>

Reply via email to