# sparse array with list [closed]

i'm trying to populate a sparse array with lists in certain positions, i tried the following code,

A = SparseArray[{i_, j_} /; 0 <= j - i <= 1 -> Avk, {10, 10 + 1}];

where Avk is 2x2 matrix, but mathematica yields that the assigned value must not be a list. i want the result to be like

where Avk and 0 are a 2x2 matrices (here is an example of dimension (3x4)), but the actual problem is (124x126) matrix.

## closed as off-topic by Dr. belisarius, bbgodfrey, ciao, Jens, Kuba♦Apr 13 '15 at 6:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Dr. belisarius, bbgodfrey, ciao
If this question can be reworded to fit the rules in the help center, please edit the question.

• As Mathematica tells you, this is not possible. Elements of a sparse array cannot be arrays themselves. It would be better if you asked about the problem you are actually trying to solve. – Szabolcs Apr 12 '15 at 16:27
• Are you trying to make a four dimensional sparse array? That is not the same thing as a two-dimensional sparse array with array elements. – Szabolcs Apr 12 '15 at 16:40
• @Szabolcs No it's just a 2 dimension matrix, as you can see in the image, it's a 3x4 matrix with elements are 2x2, in the end i need to do ArrayFlatten so this would be a 6x8 matrix ( i hope did well to describe my problem) – El Amraoui Abdelilah Apr 12 '15 at 16:47
• You can use the answer to the following question, of which this is a possible duplicate: Entering block matrices, general case doesn't work – Jens Apr 13 '15 at 2:09
• @Jens thanks man it was a great reference it worked as well – El Amraoui Abdelilah Apr 17 '15 at 1:35

Update:

... because my matrix is (214x216) so it's impossible to assign all these values one by one.

(* your 62  2X2 matrices av1 through av62 *)
avmat = Array[Subscript[Row[{av, #}], ##2] &, {62, 2, 2}];

sa = SparseArray[{Band[{1, 1}] -> avmat, Band[{1, 3}] -> avmat}];
Dimensions@sa
(* {124, 126} *)
sa[[;; 20, ;; 20]] // MatrixForm (* display a portion of sa *)


Original post:

Perhaps you can use Band:

avm1 = Array[Subscript[av1, ##] &, {2, 2}];
avm2 = Array[Subscript[av2, ##] &, {2, 2}];
avm3 = Array[Subscript[av3, ##] &, {2, 2}];

sa = SparseArray[{Band[{1, 1}] -> {avm1, avm2, avm3},
Band[{1, 3}] -> {avm1, avm2, avm3}}];
sa // MatrixForm


Or

af = ArrayFlatten[{{avm1, avm1, 0, 0}, {0, avm2, avm2, 0}, {0, 0, avm3, avm3}}];
af // MatrixForm
(* same picture as above *)

• yes man that works for the example, but the problem is that i need a dynamic code, because my matrix is (214x216) so it's impossible to assigne all these values one by one – El Amraoui Abdelilah Apr 12 '15 at 18:00
• so k goes from 1 to 62? – kglr Apr 12 '15 at 18:09
• yes you can say so, if i took k goes from 1 to 62, the finale matrix would be (124x126) since each element of the matrix is a (2x2) matrix – El Amraoui Abdelilah Apr 12 '15 at 18:11
• it was helpful, – El Amraoui Abdelilah Apr 12 '15 at 19:10