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

Matthew Brett matthew.brett at gmail.com
Thu Dec 11 12:38:18 EST 2014


Hi,

On Monday, December 8, 2014, Pierre Haessig <pierre.haessig at crans.org>
wrote:

> Hi,
>
> Le 07/12/2014 08:10, Stephan Hoyer a écrit :
> > In [5]: %timeit xray.core.utils.as_shape(x, y.shape)
> > 100000 loops, best of 3: 17 µs per loop
> >
> > Would this be a welcome addition to numpy's lib.stride_tricks? If so,
> > I will put together a PR.
> >
> >
>
> Instead of putting this function in stride_tricks (which is quite
> hidden), could it be added instead as a boolean flag to the existing
> `reshape` method ? Something like:
>
> x.reshape(y.shape, broadcast=True)
>

That might be a bit odd, because the non-broadcast version would allow
entirely different parameters for shape than the broadcast version.  For
example, what would these do?

a = np.zeros((2, 3, 4))
a.reshape((6, 4), broadcast=True)
a.reshape((2, -1), broadcast=True)

So I think 'reshape' is doing something different enough that this should
be a separate function.

Cheers,

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


More information about the NumPy-Discussion mailing list