Python Forum
Executing Scipy Tensor Product - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Executing Scipy Tensor Product (/thread-22967.html)



Executing Scipy Tensor Product - John_Doe - Dec-05-2019

Can anyone advise on how to use the Scipy TensorProduct function in Python 2.7 without having to explicitly indicate the full sequence of objects to take the product of. Below 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.


RE: Executing Scipy Tensor Product - paul18fr - Dec-06-2019

for me what you want to do is not clear

You've a (2,3) matrix size so what product do you want to perform?

Maybe such kind (without Tensorflow here)?
import numpy as np
    
N = 3    
V = (1./np.sqrt(2))*np.ones((2,N))

TP1 = V[:,0]*V[:,1]*V[:,2]
TP2 = np.prod(V)
#     
print("TP1 = {}".format(TP1))
print("TP2 = {}".format(TP2))