<div dir="ltr"><div><div><div>Hey,<br><br></div>Just a quick update. I updated the pull request and renamed `stack` into `block`. Have a look: <a href="https://github.com/numpy/numpy/pull/5057">https://github.com/numpy/numpy/pull/5057</a><br><br>I'm sticking with simple initial implementation because it's simple and does what you think it does.<br><br><br></div>Cheers,<br></div> Stefan<br><div><div><br><div><div><br><div class="gmail_quote">On Fri, Oct 31, 2014 at 2:13 PM Stefan Otte <<a href="mailto:stefan.otte@gmail.com">stefan.otte@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To make the last point more concrete the implementation could look<br>
something like this (note that I didn't test it and that it still<br>
takes some work):<br>
<br>
<br>
def bmat(obj, ldict=None, gdict=None):<br>
    return matrix(stack(obj, ldict, gdict))<br>
<br>
<br>
def stack(obj, ldict=None, gdict=None):<br>
    # the old bmat code minus the matrix calls<br>
    if isinstance(obj, str):<br>
        if gdict is None:<br>
            # get previous frame<br>
            frame = sys._getframe().f_back<br>
            glob_dict = frame.f_globals<br>
            loc_dict = frame.f_locals<br>
        else:<br>
            glob_dict = gdict<br>
            loc_dict = ldict<br>
        return _from_string(obj, glob_dict, loc_dict)<br>
<br>
    if isinstance(obj, (tuple, list)):<br>
        # [[A,B],[C,D]]<br>
        arr_rows = []<br>
        for row in obj:<br>
            if isinstance(row, N.ndarray):  # not 2-d<br>
                return concatenate(obj, axis=-1)<br>
            else:<br>
                arr_rows.append(concatenate(row, axis=-1))<br>
        return concatenate(arr_rows, axis=0)<br>
<br>
    if isinstance(obj, N.ndarray):<br>
        return obj<br>
<br>
<br>
I basically turned the old `bmat` into `stack` and removed the matrix calls.<br>
<br>
<br>
Best,<br>
 Stefan<br>
<br>
<br>
<br>
On Wed, Oct 29, 2014 at 3:59 PM, Stefan Otte <<a href="mailto:stefan.otte@gmail.com" target="_blank">stefan.otte@gmail.com</a>> wrote:<br>
> Hey,<br>
><br>
> there are several ways how to proceed.<br>
><br>
> - My proposed solution covers the 80% case quite well (at least I use<br>
> it all the time). I'd convert the doctests into unittests and we're<br>
> done.<br>
><br>
> - We could slightly change the interface to leave out the surrounding<br>
> square brackets, i.e. turning `stack([[a, b], [c, d]])` into<br>
> `stack([a, b], [c, d])`<br>
><br>
> - We could extend it even further allowing a "filler value" for non<br>
> set values and a "shape" argument. This could be done later as well.<br>
><br>
> - `bmat` is not really matrix specific. We could refactor `bmat` a bit<br>
> to use the same logic in `stack`. Except the `matrix` calls `bmat` and<br>
> `_from_string` are pretty agnostic to the input.<br>
><br>
> I'm in favor of the first or last approach. The first: because it<br>
> already works and is quite simple. The last: because the logic and<br>
> tests of both `bmat` and `stack` would be the same and the feature to<br>
> specify a string representation of the block matrix is nice.<br>
><br>
><br>
> Best,<br>
>  Stefan<br>
><br>
><br>
><br>
> On Tue, Oct 28, 2014 at 7:46 PM, Nathaniel Smith <<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>> wrote:<br>
>> On 28 Oct 2014 18:34, "Stefan Otte" <<a href="mailto:stefan.otte@gmail.com" target="_blank">stefan.otte@gmail.com</a>> wrote:<br>
>>><br>
>>> Hey,<br>
>>><br>
>>> In the last weeks I tested `np.asarray(np.bmat(....))` as `stack`<br>
>>> function and it works quite well. So the question persits:  If `bmat`<br>
>>> already offers something like `stack` should we even bother<br>
>>> implementing `stack`? More code leads to more<br>
>>> bugs and maintenance work. (However, the current implementation is<br>
>>> only 5 lines and by using `bmat` which would reduce that even more.)<br>
>><br>
>> In the long run we're trying to reduce usage of np.matrix and ideally<br>
>> deprecate it entirely. So yes, providing ndarray equivalents of matrix<br>
>> functionality (like bmat) is valuable.<br>
>><br>
>> -n<br>
>><br>
>><br>
>> _______________________________________________<br>
>> NumPy-Discussion mailing list<br>
>> <a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
>> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
>><br>
</blockquote></div></div></div></div></div></div>