Overriding other __rmul__ with your class's __mul__
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Python, is it possible for your class's __rmul__ method to override another class's __mul__ method, without making changes to the other class? This question arises since I'm writing a class for a certain type of linear operator, and I want it to be able to multiply numpy arrays using the multiplication syntax. Here is a minimal example illustrating the issue: import numpy as np class AbstractMatrix(object): def __init__(self): self.data = np.array([[1, 2],[3, 4]]) def __mul__(self, other): return np.dot(self.data, other) def __rmul__(self