Nice solution, Robert.
My solution was not idiomatic Numpy, but it was idiomatic Python:
def slice2d(arr):
xmax, ymax = arr.shape[-2:]
return (arr[...,x,y] for x in range(xmax) for y in range(ymax))
On Tue, Aug 29, 2017 at 6:47 PM, Robert Kern wrote:
> On Tue, Aug 29, 2017 at 6:03 PM
On Tue, Aug 29, 2017 at 6:03 PM, Moroney, Catherine M (398E) <
catherine.m.moro...@jpl.nasa.gov> wrote:
> Hello,
>
>
>
> I have an n-dimensional array (say (4,4,2,2)) and I wish to automatically
> extract all the (4,4) slices in it.
>
> i.e.
>
>
>
> a = numpy.arange(0, 64).reshape(4,4,2,2)
>
> sli
Hello,
I have an n-dimensional array (say (4,4,2,2)) and I wish to automatically
extract all the (4,4) slices in it.
i.e.
a = numpy.arange(0, 64).reshape(4,4,2,2)
slice1 = a[..., 0, 0]
slice2 = a[..., 0, 1]
slice3 = a[..., 1, 0]
slice4 = a[..., 1,1]
Simple enough example but in my case array “a
On Tue, Aug 29, 2017 at 4:08 AM, Neal Becker wrote:
> Transplant sounds interesting, I think I could use this. I don't
> understand though why nobody has used a more direct approach? Matlab has
> their python API https://www.mathworks.com/help/matlab/matlab-engine-for-
> python.html. This will
On Tue, Aug 29, 2017 at 1:08 PM, Neal Becker wrote:
> [...]
> [I] would guess that inside every Matlab array is a numpy array crying to be
> freed - in both cases an array is a block of memory together with shape and
> stride information. So I would hope a direct conversion could be done, at
> le
Transplant sounds interesting, I think I could use this. I don't
understand though why nobody has used a more direct approach? Matlab has
their python API
https://www.mathworks.com/help/matlab/matlab-engine-for-python.html. This
will pass Matlab arrays to/from python as some kind of opaque blob.