[Numpy-discussion] Vectorized version of numpy.linspace

Stephan Hoyer shoyer at gmail.com
Wed Nov 14 17:46:11 EST 2018


On Wed, Nov 14, 2018 at 2:35 PM Sebastian Berg <sebastian at sipsolutions.net>
wrote:

> On Wed, 2018-11-14 at 14:32 -0500, Marten van Kerkwijk wrote:
> > Code being better than words: see
> > https://github.com/numpy/numpy/pull/12388 for an implementation. The
> > change in the code proper is very small, though it is worrying that
> > it causes two rather unrelated tests too fail (even if arguably both
> > tests were wrong).
> >
> > Note that this does not give flexibility to put the axis where one
> > wants; as written, the code made putting it at the start the obvious
> > solution, as it avoids doing anything with the shapes of start and
> > stop.
>
> Hehe, my first gut feeling was the last axis to be the obvious one ;).
> This has been discussed before (but what hasn't) I believe, probably
> some old issue or even PR somewhere.
> I am mildly in favor, just because there is probably not much reason
> against an easy vectorization. Doesn't need to be advertised much in
> the docs anyway.
> Although it might be good to settle the "obvious" part in case I am not
> alone in first thinking of -1 being the obvious default. I would
> probably skip the axis argument for now, unless someone actually has a
> use case.


Indeed -- I think the best argument for adding an "axis" argument is that
it allows people to be explicit about where the axis ends up, e.g., both
np.linspace(start, stop, num=5, axis=0) and np.linspace(start, stop, num=5,
axis=-1) make their intent quite clear.

To me, axis=0 feels like the right default, matching np.concatenate and
np.stack. But NumPy already has split conventions for this sort of thing
(e.g., gufuncs add axes at the end), so I like the explicit option.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20181114/e0b65c36/attachment-0001.html>


More information about the NumPy-Discussion mailing list