title: Parameters to numpy's fromfunction
body: <p>I haven't grokked the key concepts in <code>numpy</code> yet.</p>
  
  <p>I would like to create a 3-dimensional array and populate each cell with the result of a function call - i.e. the function would be called many times with different indices and return different values.</p>
  
  <p><strong><em>Note: Since writing this question, the documentation has been updated to be clearer.</em></strong></p>
  
  <p>I could create it with zeros (or empty), and then overwrite every value with a for loop, but it seems cleaner to populate it directly from the function.</p>
  
  <p><a href="http://wiki.scipy.org/Numpy_Example_List#fromfunction" rel="noreferrer"><code>fromfunction</code></a> sounds perfect. <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfunction.html" rel="noreferrer">Reading the documentation</a> it sounds like the function gets called once per cell.</p>
  
  <p>But when I actually try it...</p>
  
  <pre><code>from numpy import *
  
  def sum_of_indices(x, y, z):
      # What type are X, Y and Z ? Expect int or duck-type equivalent.
      # Getting 3 individual arrays
      print "Value of X is:"
      print x
  
      print "Type of X is:", type(x)
      return x + y + z
  
  a = fromfunction(sum_of_indices, (2, 2, 2))
  </code></pre>
  
  <p>I expect to get something like:</p>
  
  <pre><code>Value of X is:
  0
  Type of X is: int
  Value of X is:
  1
  Type of X is: int
  </code></pre>
  
  <p>repeated 4 times.</p>
  
  <p>I get:</p>
  
  <pre><code>Value of X is:
  [[[ 0.  0.]
    [ 0.  0.]]
  
   [[ 1.  1.]
    [ 1.  1.]]]
  [[[ 0.  0.]
    [ 1.  1.]]
  
   [[ 0.  0.]
    [ 1.  1.]]]
  [[[ 0.  1.]
    [ 0.  1.]]
  
   [[ 0.  1.]
    [ 0.  1.]]]
  Type of X is: &lt;type 'numpy.ndarray'&gt;
  </code></pre>
  
  <p>The function is only called once, and seems to return the entire array as result.</p>
  
  <p>What is the correct way to populate an array based on multiple calls to a function of the indices?</p>