Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10312
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Flattening a hypermatrix into an ordinary matrix |
| Date | 2012-06-02 09:44 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jqcn9c$13b$1@smc.vnet.net> (permalink) |
On 6/1/12 at 5:19 AM, carlos@colorado.edu wrote:
>I have an n x n hypermatrix, the entries of which are m x m blocks.
>For example A below (m=3, n=2):
>A11={{B11,B12,B13},{B21,B22,B23},{B31,B32,B33}};
>A12={{C11,C12,C13},{C21,C22,C23},{C31,C32,C33}};
>A21={{D11,D12,D13},{D21,D22,D23},{D31,D32,D33}};
>A22={{E11,E12,E13},{E21,E22,E23},{E31,E32,E33}}; A={{
>A11,A12},{A21,A22}};
>I want to convert this to an ordinary n*m x n*m matrix. For the
>example I want A to become
>{{B11,B12,B13,C11,C12,C13},{B21,B22,B23,C21,C22,C23},
>{B31,B32,B33,C31,C32,C33},{D11,D12,D13,E11,E12,E13},
>{D21,D22,D23,E21,E22,E23},{D31,D32,D33,E31,E32,E33}}
>This can be easily done with C style loops as
<snip>
>but is there a more elegant way using Flatten?
Better would be to use ArrayFlatten which is specifically
designed for this task, i.e.,
In[6]:= ArrayFlatten[a]
Out[6]=
{{b11, b12, b13, c11, c12, c13}, {b21, b22, b23, c21, c22, c23},
{b31, b32, b33, c31, c32, c33}, {d11, d12, d13, e11, e12, e13},
{d21, d22, d23, e21, e22, e23}, {d31, d32, d33, e31, e32, e33}}
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Flattening a hypermatrix into an ordinary matrix Bill Rowe <readnews@sbcglobal.net> - 2012-06-02 09:44 +0000
csiph-web