python - Vector functions in SymPy -


i have such vector function. first 2 arguments n-dimensional vectors.

enter image description here

i want write function in sympy, problem begins, when need write sum.

this managed do:

w, lam, phi, theta, p, j = sp.symbols('w lam phi theta p j')  w = (1 + sp.cos(phi)*sp.cos(theta))*p lam = (1+sp.cos(phi-theta))/(2*(1+sp.cos(phi)*sp.cos(theta)))  j = -(1 - sp.sum(w * ((-lam*sp.log(lam,2)) - (1-lam)*sp.log(1-lam, 2)), 1, len(lam))) 

last line generates

typeerror                                 traceback (most recent call last) <ipython-input-19-d8b506a75004> in <module>() ----> 1 j = -(1 - sp.sum(w * ((-lam*sp.log(lam,2)) - (1-lam)*sp.log(1-lam, 2)), 1, len(lam)))  typeerror: object of type 'mul' has no len() 

but of course not real problem. real problem don't know how handle multi-dimensionality. how write such vector function in sympy?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -