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

2015-01-03 Thread Stephan Hoyer
Here is an update on a new function for broadcasting arrays to a given shape (now named np.broadcast_to). I have a pull request up for review, which has received some feedback now: https://github.com/numpy/numpy/pull/5371 There is still at least one design decision to settle: should we expose

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

2014-12-12 Thread Jaime Fernández del Río
On Thu, Dec 11, 2014 at 10:53 AM, Stephan Hoyer sho...@gmail.com wrote: On Thu, Dec 11, 2014 at 8:17 AM, Sebastian Berg sebast...@sipsolutions.net wrote: One option would also be to have something like: np.common_shape(*arrays) np.broadcast_to(array, shape) # (though I would like many

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

2014-12-12 Thread Sebastian Berg
On Fr, 2014-12-12 at 05:48 -0800, Jaime Fernández del Río wrote: On Thu, Dec 11, 2014 at 10:53 AM, Stephan Hoyer sho...@gmail.com wrote: On Thu, Dec 11, 2014 at 8:17 AM, Sebastian Berg sebast...@sipsolutions.net wrote: One option would also be

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

2014-12-12 Thread Jaime Fernández del Río
On Fri, Dec 12, 2014 at 5:57 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Fr, 2014-12-12 at 05:48 -0800, Jaime Fernández del Río wrote: On Thu, Dec 11, 2014 at 10:53 AM, Stephan Hoyer sho...@gmail.com wrote: On Thu, Dec 11, 2014 at 8:17 AM, Sebastian Berg

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

2014-12-12 Thread Sebastian Berg
On Fr, 2014-12-12 at 06:25 -0800, Jaime Fernández del Río wrote: On Fri, Dec 12, 2014 at 5:57 AM, Sebastian Berg sebast...@sipsolutions.net wrote: On Fr, 2014-12-12 at 05:48 -0800, Jaime Fernández del Río wrote: On Thu, Dec 11, 2014 at 10:53 AM, Stephan Hoyer

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

2014-12-12 Thread Stephan Hoyer
On Fri, Dec 12, 2014 at 5:48 AM, Jaime Fernández del Río jaime.f...@gmail.com wrote: np.broadcast is the Python object of the old iterator. It may be a better idea to write all of these functions using the new one, np.nditer: def common_shape(*args): return np.nditer(args).shape[::-1]

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

2014-12-12 Thread Stephan Hoyer
On Fri, Dec 12, 2014 at 6:25 AM, Jaime Fernández del Río jaime.f...@gmail.com wrote: it seems that all the functionality that has been discussed are one-liners using nditer: do we need new functions, or better documentation? I think there is utility to adding a new function or two (my

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

2014-12-12 Thread Jaime Fernández del Río
On Fri, Dec 12, 2014 at 11:28 AM, Stephan Hoyer sho...@gmail.com wrote: On Fri, Dec 12, 2014 at 5:48 AM, Jaime Fernández del Río jaime.f...@gmail.com wrote: np.broadcast is the Python object of the old iterator. It may be a better idea to write all of these functions using the new one,

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

2014-12-12 Thread Nathaniel Smith
On 12 Dec 2014 19:29, Stephan Hoyer sho...@gmail.com wrote: def common_shape(*args): Nitpick: let's call this broadcast_shape, not common_shape; it's as-or-more clear and clearly groups the related functions together. -n ___ NumPy-Discussion mailing

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

2014-12-11 Thread Pierre Haessig
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:

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

2014-12-11 Thread Nathaniel Smith
On 11 Dec 2014 14:31, Pierre Haessig pierre.haes...@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

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

2014-12-11 Thread Robert Kern
On Thu, Dec 11, 2014 at 2:47 PM, Nathaniel Smith n...@pobox.com wrote: On 11 Dec 2014 14:31, Pierre Haessig pierre.haes...@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

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

2014-12-11 Thread Pierre Haessig
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. Pierre

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

2014-12-11 Thread Sebastian Berg
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

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

2014-12-11 Thread Robert Kern
On Thu, Dec 11, 2014 at 4:17 PM, Sebastian Berg sebast...@sipsolutions.net wrote: 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.

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

2014-12-11 Thread Matthew Brett
On Sunday, December 7, 2014, Stephan Hoyer sho...@gmail.com wrote: I recently wrote function to manually broadcast an ndarray to a given shape according to numpy's broadcasting rules (using strides): https://github.com/xray/xray/commit/7aee4a3ed2dfd3b9aff7f3c5c6c68d51df2e3ff3 The same

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

2014-12-11 Thread Matthew Brett
Hi, On Monday, December 8, 2014, Pierre Haessig pierre.haes...@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) 10 loops, best of 3: 17 µs per loop Would this be a welcome addition to numpy's lib.stride_tricks?

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

2014-12-11 Thread Stephan Hoyer
On Thu, Dec 11, 2014 at 8:17 AM, Sebastian Berg sebast...@sipsolutions.net wrote: 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

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

2014-12-10 Thread Stephan Hoyer
On Sun, Dec 7, 2014 at 11:31 PM, Pierre Haessig pierre.haes...@crans.org wrote: 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) What

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

2014-12-10 Thread Nathaniel Smith
On Sun, Dec 7, 2014 at 7:10 AM, Stephan Hoyer sho...@gmail.com wrote: I recently wrote function to manually broadcast an ndarray to a given shape according to numpy's broadcasting rules (using strides): https://github.com/xray/xray/commit/7aee4a3ed2dfd3b9aff7f3c5c6c68d51df2e3ff3 The same

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

2014-12-10 Thread Stephan Hoyer
On Wed, Dec 10, 2014 at 4:00 PM, Nathaniel Smith n...@pobox.com wrote: 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. I like np.broadcast_to as a new function. We can document it alongside

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

2014-12-08 Thread Benjamin Root
I like the idea of the broadcast argument to reshape. It certainly makes sense there, and it avoids adding a new function. Probably should add a note to the docstring of broadcast_arrays, too. Ben Root On Mon, Dec 8, 2014 at 2:31 AM, Pierre Haessig pierre.haes...@crans.org wrote: Hi, Le

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

2014-12-07 Thread Pierre Haessig
Hi, Le 07/12/2014 08:10, Stephan Hoyer a écrit : In [5]: %timeit xray.core.utils.as_shape(x, y.shape) 10 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

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

2014-12-06 Thread Stephan Hoyer
I recently wrote function to manually broadcast an ndarray to a given shape according to numpy's broadcasting rules (using strides): https://github.com/xray/xray/commit/7aee4a3ed2dfd3b9aff7f3c5c6c68d51df2e3ff3 The same functionality can be done pretty straightforwardly with np.broadcast_arrays,