<div dir="ltr">Hello all, <div>numpy.vectorize is a very convenient way to build universal function from scalar functions, and handle broadcasting... A use case that is not handled is the generalization to functions already returning nd array: </div>
<div><br></div><div>For example: If foo(x,y) is a scalar function returning a array of dim k, it would be convenient to create a vectorized version of it, such that if the broadcasted shape of x and y has dimension d, then foo(x,y) returns a (d+k)-dimensional array.</div>
<div><br></div><div>For example:</div><div><font face="courier new, monospace"># Example 1 </font></div><div><font face="courier new, monospace">x = array([1,2,3])</font></div><div><font face="courier new, monospace">y = array([4,5,6])<br>
</font></div><div><font face="courier new, monospace"># foo(x,y)[i] is equal to foo(x[i], y[i]), a vector of dim k, </font></div><div><div><span style="font-family:'courier new',monospace"># Example 2 </span><br></div>
<div><font face="courier new, monospace">x = array([1,2,3])</font></div><div><font face="courier new, monospace">y = array([4,5,6])<br></font></div><div><font face="courier new, monospace"># foo(x,y[:, newaxis])[i,j] is equal to foo(x[i], y[j]), a vector of </font><span style="font-family:'courier new',monospace">dim </span><font face="courier new, monospace">k, </font></div>
</div><div><br></div><div>Does any one know if there is already a way to do this?</div><div><br></div><div>Best, <br>Sylvain</div></div>