# QuTIP tensor products

I am referring to the QuTIP package https://qutip.org/

To describe a system of 3 atoms in the ground state, I can crate the wavefunction: tensor( basis(2,0), basis(2,0), basis(2,0) )

Now suppose that I want to write a Python function that implements a system with N atoms in such a tensor product. If N=5, the system will look like:

tensor( basis(2,0), basis(2,0), basis(2,0), basis(2,0), basis(2,0) )

If N=100, you get the idea. How would I write the tensor product in a general way, for N tensor products?

good question - indeed the qutip API could use some improvements when dealing with tensor products. However, here python comes to the rescue with argument unpacking. To create a 4 qubit basis state, you can do e.g:

qp.tensor(*[qp.basis(2, 0) for _ in range(4)])


if you need more complicated arguments, you can build the list upfront and then unpack it, e.g:

args = [destroy(2)] + [qp.basis(2, 0) for _ in range(4)]
qp.tensor(*args)


just keep in mind that this:

lst = [qp.basis(2, 0)] * 4


will not work as you probably expect it - it will create a list with 4 references to the same object, not initialize 4 different objects.

Let me know if this helps.

• Thanks for the answer, this is helpful! Suppose I want to create the tensor qp.tensor( destroy(2), basis(2), basis(2), basis(2), basis(2) ) I thought I could use qp.tensor(destroy(2), *[qp.basis(2, 0) for _ in range(4)]) but this does not create a similar object. Do you know how to resolve this?
– Halo
Feb 23, 2022 at 23:56