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