# [Mathematica] Explose a matrix

1. Apr 19, 2010

### guerom00

[Mathematica] “Explose” a matrix

Hi all,

Sorry for the title
Here is what I need to do : Transform this matrix (sorry, didn't find the LaTeX for matrices; pmatrix does not work)

a b c 0 0 0 0 0 0
d e f 0 0 0 0 0 0
g h i 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

into

a 0 0 b 0 0 c 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
d 0 0 e 0 0 f 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
g 0 0 h 0 0 i 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

if you see what I mean… I looked into ArrayPad[] but my pattern is more complicated than a simple padding…
What's the best solution do that ?

TIA

Last edited: Apr 19, 2010
2. Apr 19, 2010

### tiny-tim

Hi guerom00!

The second matrix is the same as the top left corner of the first matrix, but with lots of zero rows and columns inserted.

So just permute the rows, and permute the columns.

3. Apr 19, 2010

### guerom00

Re: [Mathematica] “Explose” a matrix

Thanks for your response

Yeah… How to permute 2 rows or 2 columns ?
Nothing more “elegant” ?

4. Apr 19, 2010

### guerom00

Re: [Mathematica] “Explose” a matrix

I found this which is not bad :

5. Apr 19, 2010

### Gueygel

Re: [Mathematica] “Explose” a matrix

If

A={{1,0,0},{0,0,0},{0,0,0}}
B={{a,b,c},{d,e,f},{g,h,i}}

then your first matrix is A x B and your second matrix is B x A, where "x" means tensor product. I'm not sure if new versions of Mathematica have the "tensor product" implemented, I already use an old code made by myself for that.

6. Apr 20, 2010

### Hepth

Re: [Mathematica] “Explose” a matrix

I know if you have two matrices you can do:

A = {{a, b}, {c, d}}
B = {{1, 0, 0}, {0, 0, 0}, {0, 0, 0}}
Outer[Times, A, B] // ArrayFlatten

I think by tensor product you mean outer product.

EDIT: Changed SUM to Times (I had some for something else I was trying, TIMES is what you want.)

Last edited: Apr 20, 2010
7. Apr 20, 2010

### Gueygel

Re: [Mathematica] “Explose” a matrix

Yes, Outer[Times[]] works for tensor products of matrices.
What I use does not need ArrayFlatten...

8. Apr 20, 2010

### guerom00

Re: [Mathematica] “Explose” a matrix

Thanks

Is there a general thread for random questions on Mathematica ? I don't want to open a new thread each time…
For instance, I'm looking for a pattern (to be used in a DeleteCases[]) which match a list of zeros of arbitrary length i.e. which match {0} or {0,0} or {0,0,0}, etc…
Can someone help me ?

TIA