title: How to plot scalar functions of matrices in matplotlib involving matrix_power?
body: <p>I have the following code to plot scalar <code>x</code> vs scalar <code>f(x)</code> where there is some matrix multiplication inside the function:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from numpy.linalg import matrix_power
  P=np.array([\
   [0,0,0.5,0,0.5],\
   [0,0,1,0,0], \
   [.25,.25,0,.25,.25], \
   [0,0,.5,0,.5], \
   [0,0,0,0,1], \
   ])
  t=np.array([0,1,0,0,0])
  ones=np.array([1,1,1,1,0])
  
  def f(x):
      return t.dot(matrix_power(P,x)).dot(ones)
  x=np.arange(1,20)
  plt.plot(x, f(x))
  </code></pre>
  
  <p>Now, the function by itself works fine.</p>
  
  <pre><code>&gt;&gt;&gt; f(1)
  1.0
  &gt;&gt;&gt; f(2)
  0.75 
  </code></pre>
  
  <p>But the plotting raises the error <code>exponent must be an integer</code>. </p>
  
  <p>To put it another way, how do I evaluate this function upon an array? e.g.</p>
  
  <p><code>f(np.array([1,2]))</code></p>
  
  <p>I tried replacing the plot line with 
  <code>plt.plot(x, map(f,x))</code></p>
  
  <p>But this didn't help.</p>
  
  <p>How can I fix this?</p>