# Kronecker product in a loop

I have an Array given by

a[n_Integer] := RandomChoice[{{1, 0}, {0, 1}}, n]


I need to write a loop that takes the Kronecker product of a[[k]] & a[[k+1]], then replace a[[k+1]] with the result of the Kronecker product of a[[k]] & a[[k+1]] and go on. I use

 Table[If[k <= n - 1,
a[[k + 1]] =
KroneckerProduct[a[[k]], a[[k + 1]]]], {k, 1, n - 1}]


But it does not do the job. Any suggestion? Thanks!

• In the definition a is a function. However in the loop a is an array? Jan 14 at 16:16
• Would something like KroneckerProduct @@@ Partition[a[5], 2, 1] get you close to what you need? You can't do this calculation with a symbolic $n$. Also, a[n] will give you an array that changes every time you call the function, so you should save the output of a single call in a temporary variable to use in further code, rather than calling the random function multiple times, otherwise the a[n] on which you work will be different at every call. Jan 14 at 17:08