title: Using numpy to build an array of all combinations of two arrays
body: <p>I'm trying to run over the parameters space of a 6 parameter function to study its numerical behavior before trying to do anything complex with it, so I'm searching for an efficient way to do this.</p>
  <p>My function takes float values given in a 6-dim numpy array as input. What I tried to do initially was this:</p>
  <p>First, I created a function that takes 2 arrays and generate an array with all combinations of values from the two arrays:</p>
  <pre><code>from numpy import *
  def comb(a,b):
      c = []
      for i in a:
          for j in b:
              c.append(r_[i,j])
      return c
  </code></pre>
  <p>Then, I used <code>reduce()</code> to apply that to m copies of the same array:</p>
  <pre><code>def combs(a,m):
      return reduce(comb,[a]*m)
  </code></pre>
  <p>Finally, I evaluate my function like this:</p>
  <pre><code>values = combs(np.arange(0,1,0.1),6)
  for val in values:
      print F(val)
  </code></pre>
  <p>This works but it's <em>way</em> too slow. I know the space of parameters is huge, but this shouldn't be so slow. I have only sampled 10<sup>6</sup> (a million) points in this example and it took more than 15 seconds just to create the array <code>values</code>.</p>
  <p>Do you know any more efficient way of doing this with numpy?</p>
  <p>I can modify the way the function <code>F</code> takes it's arguments if it's necessary.</p>