Search code examples
python-3.xnumpypython-itertools

itertool for generating 2 strings for sympy


I want to be able to generate a set of Symbols using iter.product, my code looks like follow :

for m in range(0,3):
    for n in range(0,3):
       for o in range(0,3):
           for p in range(0,3):
                sub1=(m+1,n+1)
                sub2=(o+1,p+1)
                x= symbols(('C_{%d%d%d%d}')%(m+1,n+1,o+1,p+1), commutative=True)
                B=Symbol("C_{%s}" % ''.join(str(i,j) for i,j in itertools.product(sorted(sub1),sorted(sub2))))

but I get the following error : str() argument 2 must be str, not int

if I kkep only i or j the code works. The error suggest that one of the argument is not a str, thing that i don't understand.


Solution

  • I found an answer to this.

    It just needed to change the last line to :

                B=Symbol("C_{%s}" % ''.join(str((i,j)) for i,j in itertools.product(sorted(sub1),sorted(sub2))))