I was a bit surprised to discover that both meshgrid nor mgrid return fully
instantiated arrays, when simple broadcasting (ie with stride=0 for other axes)
is functionally identical and happens much, much faster.
I wrote my own function to do this:
def broadcast_mgrid(arrays):
shape = tupl
On Wed, Mar 8, 2017 at 9:48 PM, Juan Nunez-Iglesias
wrote:
> I was a bit surprised to discover that both meshgrid nor mgrid return
> fully instantiated arrays, when simple broadcasting (ie with stride=0 for
> other axes) is functionally identical and happens much, much faster.
>
>
Take a look at
Hi Warren,
ogrid doesn’t solve my problem. Note that my code returns arrays that would
evaluate as equal to the mgrid output. It’s just that they are copied in mgrid
into a giant array, instead of broadcast:
In [176]: a0, b0 = np.mgrid[:5, :5]
In [177]: a1, b1 = th.broadcast_mgrid((np.arange(
Hi, Juan.
Meshgrid can actually give what you want, but you must use the options:
copy=False and indexing=’ij’.
In [7]: %timeit np.meshgrid(np.arange(512), np.arange(512))
1000 loops, best of 3: 1.24 ms per loop
In [8]: %timeit np.meshgrid(np.arange(512), np.arange(512), copy=False)
1 loop
Ah, fantastic, thanks Per!
I'd still be interested to hear from the core devs as to why this isn't the
default, both with meshgrid and mgrid...
Juan.
On 9 Mar 2017, 6:29 PM +1100, per.brodtk...@ffi.no, wrote:
> Hi, Juan.
>
> Meshgrid can actually give what you want, but you must use the options