# Executing Scipy Tensor Product [closed]

Can anyone advise on how to use the SymPy TensorProduct function without having to explicitly indicate the full sequence of objects to take the product of. Below (for the simple case N=3) you can see one of my attempts. But the tensor products are still not coinciding, hence I am still having to write out the full sequence to get the correct answer.

import scipy
from numpy import*
import math
from sympy import I, Matrix, symbols
from sympy.physics.quantum import TensorProduct

N = 3

x = array([1/(math.sqrt(2)),1/(math.sqrt(2))])

V =[]
for i in range(1,N+1):
V.append(x)

V = array(V)

TP1 = TensorProduct(V[0],V[1],V[2])
TP2 = TensorProduct(V[:])

print TP1
print TP2


Thanks for any assistance.

• Code not working as intended is not ready for review on CodeReview@SE. That said, try printing V. – greybeard Dec 6 '19 at 3:37
• @greybeard The code runs as is above and it prints $V$. The problem is that is does not give the correct tensor product unless I explicitly write out each element of the sequence. – John Doe Dec 6 '19 at 3:44
• @JohnDoe try TP2 = TensorProduct(*V); let me know if that works or if I'm misunderstanding something – alexyorke Dec 6 '19 at 3:56
• @alexyorke That seems to works thanks! I'm not familiar with the '*v' syntax, I'm relatively new to Python. Where can I read up on this? – John Doe Dec 6 '19 at 4:00
• @JohnDoe Here is an article: stackoverflow.com/questions/36620025/… . I will post my comment as the answer which you can accept to let others know how you solved the problem – alexyorke Dec 6 '19 at 4:01

To pass a list of array arguments as individual parameters to a Python function, use the * operator:
TP1 = TensorProduct(*V)

This is equivalent to TensorProduct(V[0], V[1], V[2],...,V[n])