Clear[V0, V1, V];
Nm = 10;
\[Sigma] = {({
{0, 1.},
{1., 0}
}), ({
{0, -I},
{I, 0}
}), ({
{1., 0},
{0, -1.}
})};(*Pauli-spin matrices*)
V0 = Normal[
SparseArray[{Band[{2, 1}] -> Table[V[n], {n, 1, Nm - 1}],
Band[{1, 2}] -> Table[ConjugateTranspose[V[n]], {n, 1, Nm - 1}]},
Nm]];
V[n_] := IdentityMatrix[2] + I ({n, n, n}. \[Sigma]);
V1 = ArrayFlatten[V0];
Above is the code with fix size. In this way I can use arrayFlatten to define the normal matrix. See example below:

However, the thing will change if I use a variable input (See below).
Clear[V0, V1, V]
\[Sigma] = {({
{0, 1.},
{1., 0}
}), ({
{0, -I},
{I, 0}
}), ({
{1., 0},
{0, -1.}
})};(*Pauli-spin matrices*)
V0[Nm_] :=
Normal[SparseArray[{Band[{2, 1}] -> Table[V[n], {n, 1, Nm - 1}],
Band[{1, 2}] -> Table[ConjugateTranspose[V[n]], {n, 1, Nm - 1}]},
Nm]];
V[n_] := IdentityMatrix[2] + I ({n, n, n}. \[Sigma]);
V1[Nm_] := ArrayFlatten[V0[Nm]];
If I evaluate above, then I got error as follows:

How to solve this problem?


\[Sigma]? Please post complete code. – Henrik Schumacher Jul 20 '21 at 18:41α? If it is not necessary to show the problem, it is better to remove it, but if it is needed, can you, please, provide such detail of its definition? Thanks! – CA Trevillian Jul 20 '21 at 21:45