title: matrix subs in sympy
body: <p>I am trying to compute some symbolic expressions with matrices using sympy. The behavior of sympy function subs is strange for matrices. What I need is to take string with symbolic expression, substitute some particular matrices instead symbols in this expression and compute the results. </p>
  
  <p>For scalars the sympy.subs does the job:</p>
  
  <pre><code>import sympy as sp
  sp.sympify("x1*x2**2").subs({"x1":5,"x2":10})
  </code></pre>
  
  <p>gives 500 as expected.</p>
  
  <p>If instead scalars I use matrices like </p>
  
  <pre><code>sp.sympify("x1*x2**2").subs({"x1":sp.Matrix([[0,1],[1,0]]),"x2":sp.Matrix([[1,0],[0,1]])}
  </code></pre>
  
  <p>the result is <code>AttributeError: 'MatPow' object has no attribute 'as_base_exp'</code>. This seems strange as long as </p>
  
  <pre><code>aa,bb = sp.Matrix([[0,1],[1,0]]), sp.Matrix([[1,0],[0,1]])
  aa*bb**2
  </code></pre>
  
  <p>works as expected. </p>
  
  <p>What is the correct way to perform such calculations in sympy? </p>