title: Exponentiation a matrix by itself N times?
body: <p>I am realizing Exponentiation of a matrix using FOR:</p>
  
  <pre><code>import numpy as np
  fl=2
  cl=2
  fl2=fl
  cl2=cl
  M = random.random((fl,cl))
  M2 = M
  Result = np.zeros((fl,cl))
  Temp = np.zeros((fl,cl))
  itera = 2
  print('Matriz A:\n',M)
  print('Matriz AxA:\n',M2)
  
  for i in range (0,itera):
      for a in range(0,fl):
          for b in range (0,cl):  
              Result[a,b]+=M[a,b]*M[a,b]
              temp[a,b]=Result[a,b]
              Res[a,k]=M[a,b]
  print('Potencia:\n',temp)
  print('Matriz:\n', Result)
  </code></pre>
  
  <p>The error is that it does not perform well the multiplication in <code>Result[a,b]+=M[a,b]*M[a,b]</code> and when I save it in a temporary matrix to multiply it with the original matrix, it does not make the next jump in <code>for i in range (0,itera):</code> </p>
  
  <p>I know I can perform the function <code>np.matmul</code> 
  but I try to do it with the FOR loop</p>
  
  <p><a href="https://i.stack.imgur.com/sPQDJ.png" rel="nofollow noreferrer">Example</a></p>