[Numpy-discussion] Generalize hstack/vstack --> stack; Block matrices like in matlab
Stefan Otte
stefan.otte at gmail.com
Tue Oct 28 14:34:14 EDT 2014
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 implementation is
only 5 lines and by using `bmat` which would reduce that even more.)
Best,
Stefan
On Fri, Sep 19, 2014 at 4:47 PM, Paul Hobson <pmhobson at gmail.com> wrote:
> 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 along if you're curious.
> -p
>
> On Mon, Sep 8, 2014 at 9:55 AM, Benjamin Root <ben.root at ou.edu> wrote:
>>
>> 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
>> would be willing to share it even if I could lest I release code-thulu upon
>> the world...
>>
>> I think just having this generalize stack feature would be nice start.
>> Tetris could be built on top of that later. (Although, I do vote for at
>> least 3 or 4 dimensional stacking, if possible).
>>
>> Cheers!
>> Ben Root
>>
>>
>> On Mon, Sep 8, 2014 at 12:41 PM, Eelco Hoogendoorn
>> <hoogendoorn.eelco at gmail.com> wrote:
>>>
>>> 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 function.
>>>
>>> However, some form of nd-stack function would be neat in my opinion.
>>>
>>> On Mon, Sep 8, 2014 at 6:10 PM, Jaime Fernández del Río
>>> <jaime.frio at gmail.com> wrote:
>>>>
>>>> On Mon, Sep 8, 2014 at 7:41 AM, Sturla Molden <sturla.molden at gmail.com>
>>>> wrote:
>>>>>
>>>>> Stefan Otte <stefan.otte at gmail.com> 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 vstack. But that means a and b
>>>>> have
>>>>> to have the same number of rows, c and d must have the same rumber of
>>>>> rows,
>>>>> and hstack((a,b)) and hstack((c,d)) must have the same number of
>>>>> columns.
>>>>>
>>>>> Thus it requires a regularity like this:
>>>>>
>>>>> AAAABB
>>>>> AAAABB
>>>>> CCCDDD
>>>>> CCCDDD
>>>>> CCCDDD
>>>>> CCCDDD
>>>>>
>>>>> What if we just ignore this constraint, and only require the output to
>>>>> be
>>>>> rectangular? Now we have a 'tetris game':
>>>>>
>>>>> AAAABB
>>>>> AAAABB
>>>>> CCCCBB
>>>>> CCCCBB
>>>>> CCCCDD
>>>>> CCCCDD
>>>>>
>>>>> or
>>>>>
>>>>> AAAABB
>>>>> AAAABB
>>>>> CCCCBB
>>>>> CCCCBB
>>>>> CCCCBB
>>>>> CCCCBB
>>>>>
>>>>> This should be 'stackable', yes? Or perhaps we need another stacking
>>>>> function for this, say numpy.tetris?
>>>>>
>>>>> And while we're at it, what about higher dimensions? should there be an
>>>>> ndstack function too?
>>>>
>>>>
>>>> This is starting to look like the second time in a row Stefan tries to
>>>> extend numpy with a simple convenience function, and he gets tricked into
>>>> implementing some sophisticated algorithm...
>>>>
>>>> For his next PR I expect nothing less than an NP-complete problem. ;-)
>>>>
>>>>
>>>> Jaime
>>>>
>>>> --
>>>> (\__/)
>>>> ( O.o)
>>>> ( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
>>>> planes de dominación mundial.
>>>>
>>>> _______________________________________________
>>>> NumPy-Discussion mailing list
>>>> NumPy-Discussion at scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>>
>>>
>>>
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>>
>>
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list