[Numpy-discussion] Consider improving numpy.outer's behavior with zero-dimensional vectors

Nathaniel Smith njs at pobox.com
Tue Apr 14 15:37:54 EDT 2015

On Apr 14, 2015 2:48 PM, "Neil Girdhar" <mistersheik at gmail.com> wrote:
> Okay, but by the same token, why do we have cumsum?  Isn't it identical to
> np.add.accumulate
> — or if you're passing in multidimensional data —
> np.add.accumulate(a.flatten())
> ?
> add.accumulate feels more generic, would make the other ufunc things more
discoverable, and is self-documenting.
> Similarly, cumprod is just np.multiply.accumulate.

Yeah, but these do have several differences than np.outer:

- they get used much more
- their definitions are less obviously broken (cumsum has no obvious
definition for an n-d array so you have to pick one; outer does have an
obvious definition and np.outer got it wrong)
- they're more familiar from other systems (R, MATLAB)
- they allow for special dispatch rules (e.g. np.sum(a) will try calling
a.sum() before it tries coercing a to an ndarray, so e.g. on np.ma objects
np.sum works and np.add.accumulate doesn't. Eventually this will perhaps be
obviated by __numpy_ufunc__, but that is still some ways off.)

So the situation is much less clear cut.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150414/8599bfde/attachment.html>

More information about the NumPy-Discussion mailing list