<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 9, 2014 at 5:42 AM, Stefan Otte <span dir="ltr"><<a href="mailto:stefan.otte@gmail.com" target="_blank">stefan.otte@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey,<br>
<br>
@Josef, I wasn't aware of `bmat` and `np.asarray(np.bmat(....))` does<br>
basically what I want and what I'm already using.<br></blockquote><div><br></div><div>I never needed any tetris or anything similar except for the matched block version.</div><div><br></div><div>Just to point out two more related functions</div><div><br></div><div>scipy.sparse also has `bmat` for sparse block matrices</div><div>scipy.linalg and scipy.sparse have `block_diag` to complement bmat.</div><div><br></div><div><br></div><div>What I sometimes wish for is a sparse pseudo kronecker product as convenience to bmat, where the first (or the second) matrix contains (0,1) flags where the 1's specify where to put the blocks. </div><div>(I'm not sure what I really mean, similar to block_diag but with a different filling pattern.)</div><div><br></div><div>Josef</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Regarding the Tetris problem: that never happened to me, but stack, as<br>
Josef pointed out, can handle that already :)<br>
<br>
I like the idea of removing the redundant square brackets:<br>
    stack([[a, b], [c, d]]) --> stack([a, b], [c, d])<br>
However, if the brackets are there there is no difference between<br>
creating a `np.array` and stacking arrays with `np.stack`.<br>
<br>
If we want to get fancy and turn this PR into something bigger<br>
(working our way up to a NP-complete problem ;)) then how about this.<br>
I sometimes have arrays that look like:<br>
  AB0<br>
  0 C<br>
Where 0 is a scalar but is supposed to fill the rest of the array.<br>
Having something like 0 in there might lead to ambiguities though. What does<br>
  ABC<br>
  0D0<br>
mean? One could limit the "filler" to appear only on the left or the right:<br>
  AB0<br>
  0CD<br>
But even then the shape is not completely determined. So we could<br>
require to have one row that only consists of arrays and determines<br>
the shape. Alternatively we could have a keyword parameter `shape`:<br>
  stack([A, B, 0], [0, C, D], shape=(8, 8))<br>
<br>
Colin, with `bmat` you can do what you're asking for. Directly taken<br>
from the example:<br>
>>> np.bmat('A,B; C,D')<br>
matrix([[1, 1, 2, 2],<br>
        [1, 1, 2, 2],<br>
        [3, 4, 7, 8],<br>
        [5, 6, 9, 0]])<br>
<br>
<br>
General question: If `bmat` already offers something like `stack`<br>
should we even bother implementing `stack`? More code leads to more<br>
bugs and maintenance work.<br>
<br>
<br>
Best,<br>
 Stefan<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On Tue, Sep 9, 2014 at 12:14 AM, cjw <<a href="mailto:cjw@ncf.ca">cjw@ncf.ca</a>> wrote:<br>
><br>
> On 08-Sep-14 4:40 PM, Joseph Martinot-Lagarde wrote:<br>
>> Le 08/09/2014 15:29, Stefan Otte a écrit :<br>
>>> Hey,<br>
>>><br>
>>> quite often I work with block matrices. Matlab offers the convenient notation<br>
>>><br>
>>>       [ a b; c d ]<br>
> This would appear to be a desirable way to go.<br>
><br>
> Numpy has something similar for strings.  The above is neater.<br>
><br>
> Colin W.<br>
>>> to stack matrices. The numpy equivalent is kinda clumsy:<br>
>>><br>
>>> vstack([hstack([a,b]), hstack([c,d])])<br>
>>><br>
>>> I wrote the little function `stack` that does exactly that:<br>
>>><br>
>>>       stack([[a, b], [c, d]])<br>
>>><br>
>>> In my case `stack` replaced `hstack` and `vstack` almost completely.<br>
>>><br>
>>> If you're interested in including it in numpy I created a pull request<br>
>>> [1]. I'm looking forward to getting some feedback!<br>
>>><br>
>>><br>
>>> Best,<br>
>>>    Stefan<br>
>>><br>
>>><br>
>>><br>
>>> [1] <a href="https://github.com/numpy/numpy/pull/5057" target="_blank">https://github.com/numpy/numpy/pull/5057</a><br>
>>><br>
>> The outside brackets are redundant, stack([[a, b], [c, d]]) should be<br>
>> stack([a, b], [c, d])<br>
>><br>
>> _______________________________________________<br>
>> NumPy-Discussion mailing list<br>
>> <a href="mailto:NumPy-Discussion@scipy.org">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>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">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>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">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>
</div></div></blockquote></div><br></div></div>