In addition to Natas' answer, you could also try:
kp[m_, k_] := Nest[KroneckerProduct[#, m] &, m, k - 1]
or
kp[m_List, k_Integer?Positive] := Nest[KroneckerProduct[#, m] &, m, k - 1]
These should give you the exact same answer. Using Nest
doesn't really save you any characters over Table
, but it is a useful function so I thought I'd use it here. Nest
applies the function (KroneckerProduct
here) repeatedly to the previous output of Nest
. I also use k - 1
so that when you enter 1 for k
, you just get back m
.
In the second one I'm just showing how you can add checks to the function so that it only runs if m
is a List
and k
is an Integer
greater than 0. It might not matter here, but I often end up running code where I accidentally feed a function the wrong kind of data and then Mathematica sits there printing errors until I abort.
KroneckerPower[m_, k_] := KroneckerProduct @@ Table[m, k]
$\endgroup$KroneckerPower[m_, 1] := m
should do what you expect. $\endgroup$