title: Apply function returning a 1D array to all elements of numpy array
body: <p>Say I have an array of <code>d</code> dimensions, and I want to apply a function which returns a 1D array to each element, yielding a <code>d+1</code>-dimensional array. Very much as an embedding lookup works. For instance:</p>
  
  <pre><code>def f(x):
      return np.array([x * i for i in range(6)])
  
  m = np.random.randint(0,10, (2,3,4,5))
  
  g = np.vectorize(f)
  h = np.vectorize(f, otypes=[np.ndarray])
  </code></pre>
  
  <p>I expect <code>n=g(m)</code> to have shape <code>(2,3,4,5,6)</code> just as if I had written 4 <code>for</code> loops, applying <code>f</code> to each element in <code>m</code>.</p>
  
  <p>However, <code>g</code> raises an error: <code>ValueError: setting an array element with a sequence.</code> and <code>h</code> returns an odd array ending like:</p>
  
  <pre><code>...
  [array([0, 9, 18, 27, 36, 45, 54, 63, 72]),
  array([0, 5, 10, 15, 20, 25, 30, 35, 40]),
  array([0, 7, 14, 21, 28, 35, 42, 49, 56]), ...,
  array([0, 1, 2, 3, 4, 5, 6, 7, 8]),
  array([0, 4, 8, 12, 16, 20, 24, 28, 32]),
  array([0, 3, 6, 9, 12, 15, 18, 21, 24])]]]], dtype=object)
  </code></pre>
  
  <p>which I can't change to what I expect.</p>
  
  <p>I get @hpaulj's comment, I just can't find how to do otherwise.</p>