4
$\begingroup$

I have a question that I suspect is trivial, but I have not stumbled onto any functions that have made such a solution obvious to me. Consider an array of the following form:

$\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} & a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34} \\ a_{41} & a_{42} & a_{43} & a_{44} \\ \end{pmatrix}$

I want a simple way to partition this into matrices with identical dimension, which in this case, could be a set of four 2x2 matrices, resulting in

$\begin{pmatrix} \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix} & \begin{pmatrix} a_{13} & a_{14} \\ a_{23} & a_{24} \\ \end{pmatrix} \\ \begin{pmatrix} a_{31} & a_{32} \\ a_{41} & a_{42} \\ \end{pmatrix} & \begin{pmatrix} a_{33} & a_{34} \\ a_{43} & a_{44} \\ \end{pmatrix} \end{pmatrix}$

Now, to generalize: I want a method to partition an $N\times N$ matrix into identical $d\times d$ submatrices, in exactly the way outlined here, and we assume of course that $d$ divides $N$. Could someone offer such a technique? Thanks in advance!

$\endgroup$
2
  • $\begingroup$ Sorry, but unless I'm misunderstanding you this won't work in general. Consider the case Array[a, {8,8}], which I can reshape into a collection of 4x4 matrix of 2x2 matrices with ArrayReshape[Array[a, {8,8}], {2,2,2,2,2,2}]. The elements in this case will be partitioned incorrectly, as you can easily verify. Perhaps I'm not getting it? $\endgroup$
    – miggle
    Commented Sep 28, 2016 at 6:40
  • $\begingroup$ Correy has been quickier than I. $\endgroup$ Commented Sep 28, 2016 at 7:45

2 Answers 2

7
$\begingroup$

Partition does exactly what you want:

mat = RandomInteger[{0, 9}, {10, 10}];

enter image description here

Partition[mat, {5, 5}]

enter image description here

Partition[mat, {2, 2}]

enter image description here

$\endgroup$
1
  • $\begingroup$ As suspected, with the right function the answer is trivial! Thanks very much friend :) $\endgroup$
    – miggle
    Commented Sep 28, 2016 at 16:06
3
$\begingroup$

Sorry, I will not give explanation because I am in hurry

 m = Table[Subscript[a, i, j], {i, 1, 4}, {j, 1, 4}]
 m // MatrixForm  
 Flatten[m]
 l = Partition[m, {2, 2}]
 l // MatrixForm

In the same time I think all this is self explanatory

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.