[Numpy-discussion] Generalized universal functions returning higher-dimensional arrays.
Sylvain Corlay
sylvain.corlay at gmail.com
Tue Apr 15 18:00:56 EDT 2014
Hello all,
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:
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.
For example:
# Example 1
x = array([1,2,3])
y = array([4,5,6])
# foo(x,y)[i] is equal to foo(x[i], y[i]), a vector of dim k,
# Example 2
x = array([1,2,3])
y = array([4,5,6])
# foo(x,y[:, newaxis])[i,j] is equal to foo(x[i], y[j]), a vector of dim k,
Does any one know if there is already a way to do this?
Best,
Sylvain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140415/c34cba1a/attachment.html>
More information about the NumPy-Discussion
mailing list