title: What does it mean to have an index to scalar variable error? python
body: <pre><code>import numpy as np
  
  with open('matrix.txt', 'r') as f:
      x = []
      for line in f:
          x.append(map(int, line.split()))
  f.close()
  
  a = array(x)
  
  l, v = eig(a)
  
  exponent = array(exp(l))
  
  L = identity(len(l))
  
  for i in xrange(len(l)):
      L[i][i] = exponent[0][i]
  
  print L
  </code></pre>
  <ol>
  <li><p>My code opens up a text file containing a matrix:<br />
  <code>1 2</code><br />
  <code>3 4</code><br />
  and places it in list <code>x</code> as integers.</p>
  </li>
  <li><p>The list <code>x</code> is then converted into an array <code>a</code>.</p>
  </li>
  <li><p>The eigenvalues of <code>a</code> are placed in <code>l</code> and the eigenvectors are placed in <code>v</code>.</p>
  </li>
  <li><p>I then want to take the exp(a) and place it in another array <code>exponent</code>.</p>
  </li>
  <li><p>Then I create an identity matrix <code>L</code> of whatever length <code>l</code> is.</p>
  </li>
  <li><p>My for loop is supposed to take the values of <code>exponent</code> and replace the 1's across the diagonal of the identity matrix but I get an error saying</p>
  <blockquote>
  <p><code>invalid index to scalar variable</code>.</p>
  </blockquote>
  </li>
  </ol>
  <p>What is wrong with my code?</p>