title: How do I create a numpy array using a function?
body: <p>I am using <code>np.fromfunction</code> to create an array of a specific sized based on a function. It looks like this:</p>
  
  <pre><code>import numpy as np
  test = [[1,0],[0,2]]
  f = lambda i, j: sum(test[i])
  matrix = np.fromfunction(f, (len(test), len(test)), dtype=int)
  </code></pre>
  
  <p>However, I receive the following error:</p>
  
  <pre><code>TypeError: only integer arrays with one element can be converted to an index
  </code></pre>