Given a normal matrix, for example
m = Array[a,{4,4}]
which has dimensions {4,4}
, I can partition it by using:
m2 = Partition[m,{2,2}],
which has dimensions {2,2,2,2}
.
Now, if m
is a sparse array, for example:
m = SparseArray[Table[{i,i}->i,{i,1,4}],{4,4}]
I would like to be able to partition it in a similar manner but with the result being a sparse matrix. The command Partition
always yields a dense matrix.
Of course, I could do something like:
SparseArray[ArrayRules[Partition[m,{2,2}]]]
but it would be inefficient since it creates a dense matrix inbetween.
m=SparseArray[{i_,i_}:>i,{4,4}]
$\endgroup$SparseArray@(Partition[m, {2, 2}])
? $\endgroup$SparseArray@Partition[m,{2,2}]
would first applyPartition[#,{2,2}]&
to the sparse array, converting it to a dense array, and then reconvert it into another sparse array. $\endgroup$