[Numpy-discussion] What's the difference between calling __mul__ and *?
lee.will at gmail.com
Fri Jun 7 12:30:18 EDT 2013
Can somebody tell me why these operations are not the same in numpy?
In : a = numpy.array([1, 2, 3.])
In : matrix = numpy.matrix([[1, 2, 3.], [4, 5, 6], [7, 8, 9]])
In : a.__mul__(matrix)
matrix([[ 1., 4., 9.],
[ 4., 10., 18.],
[ 7., 16., 27.]])
In : a * matrix
matrix([[ 30., 36., 42.]])
Essentially I'm trying to extend from numpy.ndarray. From my subclass
__mul__ I'd like to call the parent's __mul__ method. I ran into
problem when I'm trying to call super(SubArrayClass, self).__mul__()
method when working with a matrix. I also can't think of a way to use
operator.mul() due to the subclass nature. Is there any way to make
Any help is greatly appreciated.
More information about the NumPy-Discussion