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

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}}];
  • $\begingroup$ Can you show what it should look like? Use Table once? $\endgroup$
    – MikeY
    Sep 16, 2022 at 16:55
  • $\begingroup$ 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 $\endgroup$
    – Lacia
    Sep 16, 2022 at 16:57
  • $\begingroup$ @MikeY see my edit $\endgroup$
    – yarchik
    Sep 16, 2022 at 16:59
  • $\begingroup$ @lilyric Why don't you answer, just comment? $\endgroup$
    – yarchik
    Sep 16, 2022 at 17:05
  • $\begingroup$ 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. $\endgroup$
    – Lacia
    Sep 16, 2022 at 17:12

1 Answer 1


One can use


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.