title: Using Numpy Vectorize on Functions that Return Vectors
body: <p><code>numpy.vectorize</code> takes a function f:a->b and turns it into g:a[]->b[].</p>
  
  <p>This works fine when <code>a</code> and <code>b</code> are scalars, but I can't think of a reason why it wouldn't work with b as an <code>ndarray</code> or list, i.e. f:a->b[] and g:a[]->b[][]</p>
  
  <p>For example:</p>
  
  <pre><code>import numpy as np
  def f(x):
      return x * np.array([1,1,1,1,1], dtype=np.float32)
  g = np.vectorize(f, otypes=[np.ndarray])
  a = np.arange(4)
  print(g(a))
  </code></pre>
  
  <p>This yields:</p>
  
  <pre><code>array([[ 0.  0.  0.  0.  0.],
         [ 1.  1.  1.  1.  1.],
         [ 2.  2.  2.  2.  2.],
         [ 3.  3.  3.  3.  3.]], dtype=object)
  </code></pre>
  
  <p>Ok, so that gives the right values, but the wrong dtype.  And even worse:</p>
  
  <pre><code>g(a).shape
  </code></pre>
  
  <p>yields:</p>
  
  <pre><code>(4,)
  </code></pre>
  
  <p>So this array is pretty much useless.  I know I can convert it doing:</p>
  
  <pre><code>np.array(map(list, a), dtype=np.float32)
  </code></pre>
  
  <p>to give me what I want:</p>
  
  <pre><code>array([[ 0.,  0.,  0.,  0.,  0.],
         [ 1.,  1.,  1.,  1.,  1.],
         [ 2.,  2.,  2.,  2.,  2.],
         [ 3.,  3.,  3.,  3.,  3.]], dtype=float32)
  </code></pre>
  
  <p>but that is neither efficient nor pythonic.  Can any of you guys find a cleaner way to do this?  </p>
  
  <p>Thanks in advance!</p>