title: How to quickly fill a numpy array with values from separate calls to a function
body: <p>I want to fill a numpy array with generated values. These values are generated by a generator function. The array length is not too long, &lt;100 usually, but this array is generated many times, so I wanted to know if it can be optimized with some fancy usage of numpy.</p>
  
  <p>So far I can already do it with vanilla python:</p>
  
  <pre><code>def generate():
     return generated_data
  
  array = np.asarray([generate() for _ in range(array_length)])
  </code></pre>
  
  <p>I've also tried to use <code>np.full(shape, fill_value)</code>:</p>
  
  <pre><code>np.full((array_length, generated_data_size), generate())
  </code></pre>
  
  <p>But this is calls the <code>generate()</code> function only once, not once for every index in the array.</p>
  
  <p>I've also tried <code>np.vectorize()</code>, but I couldn't make it generate a appropriately shaped array.</p>