[Numpy-discussion] Add a function to broadcast arrays to a given shape to numpy's stride_tricks?

Robert Kern robert.kern at gmail.com
Thu Dec 11 10:52:44 EST 2014


On Thu, Dec 11, 2014 at 2:47 PM, Nathaniel Smith <njs at pobox.com> wrote:
>
> On 11 Dec 2014 14:31, "Pierre Haessig" <pierre.haessig at crans.org> wrote:
> >
> >
> > Le 11/12/2014 01:00, Nathaniel Smith a écrit :
> > > Seems like a useful addition to me -- I've definitely wanted this in
> > > the past. I agree with Stephan that reshape() might not be the best
> > > place, though; I wouldn't think to look for it there.
> > >
> > > Two API ideas, which are not mutually exclusive:
> > >
> > > [...]
> > >
> > > 2) Add a broadcast_to(arr, shape) function, which broadcasts the array
> > > to exactly the shape given, or else errors out if this is not
> > > possible.
> > That's also possible. Then there could be a point in `reshape`
docstring.
> >
> > Could this function be named `broadcast` instead of `broadcast_to` ?
> > (in coherence with `reshape`)
>
> It could, but then there wouldn't be much to distinguish it from
broadcast_arrays. Broadcasting is generally a symmetric operation - see
broadcast_arrays or arr1 + arr2. So the 'to' is there to give a clue that
this function is not symmetric, and rather has a specific goal in mind.

And we already have a numpy.broadcast() function.

http://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast.html

--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141211/c2f40ea7/attachment.html>


More information about the NumPy-Discussion mailing list