Skip to content

Commit cfc78fa

Browse files
committed
BUG: solve issue numpy#2649.
The issue is similar to numpy#473, multipliaction of a matrix and a column-vector returns a row-vector. That solution is to convert 1d array, list, tuple to matrix before multiplying. What causes numpy#2649 is that matrix will use dot function which is inherited from ndarray. My solution is to use __mul__ function instead. It will throw an error when user try to multiply a squre matrix and a 1d array.
1 parent fd6f038 commit cfc78fa

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎numpy/matrixlib/defmatrix.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def __mul__(self, other):
334334
return N.dot(self, other)
335335
return NotImplemented
336336

337+
dot = __mul__
338+
337339
def __rmul__(self, other):
338340
return N.dot(other, self)
339341

@@ -385,6 +387,7 @@ def _collapse(self, axis):
385387
return self[0,0]
386388
else:
387389
return self
390+
388391

389392
# Necessary because base-class tolist expects dimension
390393
# reduction by x[0]

0 commit comments

Comments
 (0)