[Numpy-discussion] Passing multiple output arguments to ufunc

Jaime Fernández del Río jaime.frio at gmail.com
Thu Oct 16 23:43:12 EDT 2014

There is an oldish feature request in github
(https://github.com/numpy/numpy/issues/4752), complaining about it not
being possible to pass multiple output arguments to a ufunc using
keyword arguments.

You can pass them all as positional arguments:

>>> out1 = np.empty(1)
>>> out2 = np.empty(1)
>>> np.modf([1.333], out1, out2)
(array([ 0.333]), array([ 1.]))

You can also pass the first as a kwarg if you leave the others unspecified:

>>> np.modf([1.333], out=out1)
(array([ 0.333]), array([ 1.]))

You can also use None in a positional argument to leave some of the
output arguments unspecified:

>>> np.modf([1.3333], None, out2)
(array([ 0.3333]), array([ 1.]))

But you cannot do something like

>>> np.modf([1.333], out=(out1, out2))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: return arrays must be of ArrayType

Would this behavior make sense? The idea would be to allow a tuple as
a valid input for the 'out=' kwarg. It would have to have a length
exactly matching the number of output arguments, and its items would
have to be either arrays or None.

For backwards compatibility we probably should still allow a single
array to mean the first output argument, even if the ufunc has
multiple outputs.

Any other thoughts?


( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.

More information about the NumPy-Discussion mailing list