Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2016-01-09 Thread Gyro Funch
On 1/9/2016 4:58 AM, Stefan Otte wrote: > Hey, > > one of my new year's resolutions is to get my pull requests > accepted (or closed). So here we go... > > Here is the update pull request: > https://github.com/numpy/numpy/pull/5057 Here is the docstring: > https://github.com/sotte/numpy/commit/

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2016-01-09 Thread Stefan Otte
Hey, one of my new year's resolutions is to get my pull requests accepted (or closed). So here we go... Here is the update pull request: https://github.com/numpy/numpy/pull/5057 Here is the docstring: https://github.com/sotte/numpy/commit/3d4c5d19a8f15b35df50d945b9c8853b683f7ab6#diff-2270128d50ff

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2015-05-10 Thread Stefan Otte
Hey, Just a quick update. I updated the pull request and renamed `stack` into `block`. Have a look: https://github.com/numpy/numpy/pull/5057 I'm sticking with simple initial implementation because it's simple and does what you think it does. Cheers, Stefan On Fri, Oct 31, 2014 at 2:13 PM Ste

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-10-31 Thread Stefan Otte
To make the last point more concrete the implementation could look something like this (note that I didn't test it and that it still takes some work): def bmat(obj, ldict=None, gdict=None): return matrix(stack(obj, ldict, gdict)) def stack(obj, ldict=None, gdict=None): # the old bmat co

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-10-29 Thread Stefan Otte
Hey, there are several ways how to proceed. - My proposed solution covers the 80% case quite well (at least I use it all the time). I'd convert the doctests into unittests and we're done. - We could slightly change the interface to leave out the surrounding square brackets, i.e. turning `stack([

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-10-28 Thread Nathaniel Smith
On 28 Oct 2014 18:34, "Stefan Otte" wrote: > > Hey, > > In the last weeks I tested `np.asarray(np.bmat())` as `stack` > function and it works quite well. So the question persits: If `bmat` > already offers something like `stack` should we even bother > implementing `stack`? More code leads to

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-10-28 Thread Stefan Otte
Hey, In the last weeks I tested `np.asarray(np.bmat())` as `stack` function and it works quite well. So the question persits: If `bmat` already offers something like `stack` should we even bother implementing `stack`? More code leads to more bugs and maintenance work. (However, the current im

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-19 Thread Paul Hobson
Hey Ben, Side note: I've had to do the same thing for stitching curvilinear model grid coordinates together. Usings pandas DataFrames indexed by `i` and `j` is really good for this. You can offset the indices directly, unstack the DF, and the pandas will align for you. Happy to send an example al

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-09 Thread josef.pktd
On Tue, Sep 9, 2014 at 8:30 AM, wrote: > > > > On Tue, Sep 9, 2014 at 5:42 AM, Stefan Otte wrote: > >> Hey, >> >> @Josef, I wasn't aware of `bmat` and `np.asarray(np.bmat())` does >> basically what I want and what I'm already using. >> > > I never needed any tetris or anything similar except

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-09 Thread josef.pktd
On Tue, Sep 9, 2014 at 5:42 AM, Stefan Otte wrote: > Hey, > > @Josef, I wasn't aware of `bmat` and `np.asarray(np.bmat())` does > basically what I want and what I'm already using. > I never needed any tetris or anything similar except for the matched block version. Just to point out two mor

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-09 Thread Stefan Otte
Hey, @Josef, I wasn't aware of `bmat` and `np.asarray(np.bmat())` does basically what I want and what I'm already using. Regarding the Tetris problem: that never happened to me, but stack, as Josef pointed out, can handle that already :) I like the idea of removing the redundant square brack

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread cjw
On 08-Sep-14 4:40 PM, Joseph Martinot-Lagarde wrote: > Le 08/09/2014 15:29, Stefan Otte a écrit : >> Hey, >> >> quite often I work with block matrices. Matlab offers the convenient notation >> >> [ a b; c d ] This would appear to be a desirable way to go. Numpy has something similar for str

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Joseph Martinot-Lagarde
Le 08/09/2014 15:29, Stefan Otte a écrit : > Hey, > > quite often I work with block matrices. Matlab offers the convenient notation > > [ a b; c d ] > > to stack matrices. The numpy equivalent is kinda clumsy: > > vstack([hstack([a,b]), hstack([c,d])]) > > I wrote the little function `stack` t

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Joseph Martinot-Lagarde
Le 08/09/2014 16:41, Sturla Molden a écrit : > Stefan Otte wrote: > >> stack([[a, b], [c, d]]) >> >> In my case `stack` replaced `hstack` and `vstack` almost completely. >> >> If you're interested in including it in numpy I created a pull request >> [1]. I'm looking forward to getting some fe

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Stephan Hoyer
On Mon, Sep 8, 2014 at 10:00 AM, Benjamin Root wrote: > Btw, on a somewhat related note, whoever can implement ndarray to be able > to use views from other ndarrays stitched together would get a fruit basket > from me come the holidays and possibly naming rights for the next kid... > Ben, you sh

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Benjamin Root
Btw, on a somewhat related note, whoever can implement ndarray to be able to use views from other ndarrays stitched together would get a fruit basket from me come the holidays and possibly naming rights for the next kid... Cheers! Ben Root On Mon, Sep 8, 2014 at 12:55 PM, Benjamin Root wrote: >

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Benjamin Root
A use case would be "image stitching" or even data tiling. I have had to implement something like this at work (so, I can't share it, unfortunately) and it even goes so far as to allow the caller to specify how much the tiles can overlap and such. The specification is ungodly hideous and I doubt I

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Eelco Hoogendoorn
Sturla: im not sure if the intention is always unambiguous, for such more flexible arrangements. Also, I doubt such situations arise often in practice; if the arrays arnt a grid, they are probably a nested grid, and the code would most naturally concatenate them with nested calls to a stacking fun

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread josef.pktd
On Mon, Sep 8, 2014 at 12:10 PM, Jaime Fernández del Río < jaime.f...@gmail.com> wrote: > On Mon, Sep 8, 2014 at 7:41 AM, Sturla Molden > wrote: > >> Stefan Otte wrote: >> >> > stack([[a, b], [c, d]]) >> > >> > In my case `stack` replaced `hstack` and `vstack` almost completely. >> > >> > If

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Nathaniel Smith
On 8 Sep 2014 10:42, "Sturla Molden" wrote: > > Stefan Otte wrote: > > > stack([[a, b], [c, d]]) > > > > In my case `stack` replaced `hstack` and `vstack` almost completely. > > > > If you're interested in including it in numpy I created a pull request > > [1]. I'm looking forward to getting

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Jaime Fernández del Río
On Mon, Sep 8, 2014 at 7:41 AM, Sturla Molden wrote: > Stefan Otte wrote: > > > stack([[a, b], [c, d]]) > > > > In my case `stack` replaced `hstack` and `vstack` almost completely. > > > > If you're interested in including it in numpy I created a pull request > > [1]. I'm looking forward to

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread josef.pktd
On Mon, Sep 8, 2014 at 10:41 AM, Sturla Molden wrote: > Stefan Otte wrote: > > > stack([[a, b], [c, d]]) > > > > In my case `stack` replaced `hstack` and `vstack` almost completely. > > > > If you're interested in including it in numpy I created a pull request > > [1]. I'm looking forward to

Re: [Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Sturla Molden
Stefan Otte wrote: > stack([[a, b], [c, d]]) > > In my case `stack` replaced `hstack` and `vstack` almost completely. > > If you're interested in including it in numpy I created a pull request > [1]. I'm looking forward to getting some feedback! As far as I can see, it uses hstack and vsta

[Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab

2014-09-08 Thread Stefan Otte
Hey, quite often I work with block matrices. Matlab offers the convenient notation [ a b; c d ] to stack matrices. The numpy equivalent is kinda clumsy: vstack([hstack([a,b]), hstack([c,d])]) I wrote the little function `stack` that does exactly that: stack([[a, b], [c, d]]) In my ca