Repository: sympy/sympy

Issue:
Incorrect lambdify of constant times matrix symbol
```
>>> A = MatrixSymbol("A", 3, 3)
>>> f = lambdify(A, 2*A)
>>> import numpy as np
>>> f(np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<lambdifygenerated-4>", line 2, in _lambdifygenerated
    return ((2).dot(A))
AttributeError: 'int' object has no attribute 'dot'
>>> import inspect
>>> print(inspect.getsource(f))
def _lambdifygenerated(A):
    return ((2).dot(A))

```

Discussion:

Patch:
diff --git a/sympy/printing/pycode.py b/sympy/printing/pycode.py
index 98d9e1ab87..fd70c73ab2 100644
--- a/sympy/printing/pycode.py
+++ b/sympy/printing/pycode.py
@@ -7,9 +7,9 @@
 
 from collections import defaultdict
 from itertools import chain
-from sympy.core import S
-from .codeprinter import CodePrinter
+from sympy.core import S, Number, Symbol
 from .precedence import precedence
+from .codeprinter import CodePrinter
 
 _kw_py2and3 = {
     'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif',
@@ -493,6 +493,8 @@ def _print_seq(self, seq):
 
     def _print_MatMul(self, expr):
         "Matrix multiplication printer"
+        if isinstance(S(expr.args[0]), (Number, Symbol)):
+            return '({0})'.format(').dot('.join([self._print(expr.args[1]), self._print(expr.args[0])]))
         return '({0})'.format(').dot('.join(self._print(i) for i in expr.args))
 
     def _print_MatPow(self, expr):


Test patch:
diff --git a/sympy/utilities/tests/test_lambdify.py b/sympy/utilities/tests/test_lambdify.py
index 223bbaf86c..618ffac683 100644
--- a/sympy/utilities/tests/test_lambdify.py
+++ b/sympy/utilities/tests/test_lambdify.py
@@ -1125,3 +1125,11 @@ def test_issue_15654():
     f = lambdify((n, l, r, Z), hydrogen.R_nl(n, l, r, Z))
     scipy_value = f(nv, lv, rv, Zv)
     assert abs(sympy_value - scipy_value) < 1e-15
+
+def test_issue_15827():
+    if not numpy:
+        skip("numpy not installed")
+    A = MatrixSymbol("A", 3, 3)
+    f = lambdify(A, 2*A)
+    assert numpy.array_equal(f(numpy.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])), \
+    numpy.array([[2, 4, 6], [2, 4, 6], [2, 4, 6]]))