Re: [Numpy-discussion] selecting all 2-d slices out of n-dimensional array

2017-08-29 Thread John Ladasky
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

Re: [Numpy-discussion] selecting all 2-d slices out of n-dimensional array

2017-08-29 Thread Robert Kern
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

[Numpy-discussion] selecting all 2-d slices out of n-dimensional array

2017-08-29 Thread Moroney, Catherine M (398E)
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

Re: [Numpy-discussion] Interface numpy arrays to Matlab?

2017-08-29 Thread Chris Barker
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

Re: [Numpy-discussion] Interface numpy arrays to Matlab?

2017-08-29 Thread Andras Deak
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

Re: [Numpy-discussion] Interface numpy arrays to Matlab?

2017-08-29 Thread Neal Becker
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.