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

Sebastian Berg sebastian at sipsolutions.net
Thu Dec 11 11:17:10 EST 2014


On Do, 2014-12-11 at 16:56 +0100, Pierre Haessig wrote:
> Le 11/12/2014 16:52, Robert Kern a écrit :
> >
> > And we already have a numpy.broadcast() function.
> >
> > http://docs.scipy.org/doc/numpy/reference/generated/numpy.broadcast.html
> True, I once read the docstring of this function. but never used it though.
> 

I am not sure it is really the right thing for most things since it
returns an old style iterator. On the other hand arrays with 0-strides
need a bit more care (if we add this top level, one might have copy=True
as a default or so?).
Also because of that it is currently limited to NPY_MAXARGS (32).
Personally, I would like to see this type of functionality implemented
in C, and may be willing to help with it. This kind of code exists in
enough places in numpy so it can be stolen pretty readily. One option
would also be to have something like:

np.common_shape(*arrays)
np.broadcast_to(array, shape)
# (though I would like many arrays too) 

and then broadcast_ar rays could be implemented in terms of these two.

Just some thoughts,

Sebastian

> Pierre
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141211/28214e7c/attachment.sig>


More information about the NumPy-Discussion mailing list