# Certain block matrix

A block matrix like $$m_{(ij),(kl)}=\delta_{ik}\delta_{jl}$$ can be constructed as

L=3;
id=IdentityMatrix[L];
m=KroneckerProduct[id, id];


But how to construct $$m_{(ij),(kl)}=\delta_{ik}\delta_{jl}(1-\delta_{ij})$$ without explicitly using Table? With table is can be constructed as

t=Table[KroneckerDelta[i, k] KroneckerDelta[j, l] (1 - KroneckerDelta[i, j]), {i, L}, {j, L}, {k, L}, {l, L}];
m = Flatten[Tph, {{1, 2}, {3, 4}}];

• Can you show what it should look like? Use Table once? Sep 16, 2022 at 16:55
• m1=Array[KroneckerDelta[#1,#2]KroneckerDelta[#3,#4](1-KroneckerDelta[#1,#3])&,{L,L,L,L}]//ArrayFlatten and m2=TensorProduct[id, id]TensorTranspose[TensorProduct[1 - id, Array[1 &, {L, L}]], {1, 3, 2, 4}]//ArrayFlatten, then m1===m2 returns True Sep 16, 2022 at 16:57
• @MikeY see my edit Sep 16, 2022 at 16:59
• @lilyric Why don't you answer, just comment? Sep 16, 2022 at 17:05
• Acturally I don't know what do you mean by "without explicitly using Table". Array can be regarded as an anonymous version of Table, or using Tensor* functions re-write your expression, or construct it directly like the answer of @user293787. Sep 16, 2022 at 17:12

One can use

DiagonalMatrix[1-Flatten[IdentityMatrix[L]]]