sympy

Installing github version of package with Anaconda

青春壹個敷衍的年華 提交于 2019-12-05 22:17:02
问题 I have Sympy installed with Anaconda , my version (of Sympy) is 0.7.6 . I want to be able to use the git version of Sympy. Do you know how can I tell to Anaconda to substitute the 2 versions ? I've tried using the git clone command, but the Sympy folder from git and Anaconda doesn't look the same at all, so I can't replace one with another. git clone git://github.com/sympy/sympy.git Is there a command like : "conda update-git sympy" ? I found that answer, but I didn't understand how to do it.

call lambdify in a loop, avoid explicitly call

此生再无相见时 提交于 2019-12-05 21:54:34
I have this code: var = ['a','b','c'] arr = np.array([ [1,2,3,4,5,6,7,8,9], [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9] ]) y = np.hsplit(arr,len(var)) newdict = {} for idx,el in enumerate(y): newdict[str(var[idx])] = el print(newdict) I am splitting the array in order to have 3 new arrays, one for each variable in the var list. Then , I am creating a new dictionary in order to assign to every variable the corresponding array.So, my result now is: {'a': array([[ 1. , 2. , 3. ], [ 0.1, 0.2, 0.3]]), 'b': array([[ 4. , 5. , 6. ], [ 0.4, 0.5, 0.6]]), 'c': array([[ 7. , 8. , 9. ], [ 0.7, 0.8, 0.9]])} Now,

How to use sympy.physics.quantum Commutator?

送分小仙女□ 提交于 2019-12-05 21:44:20
I want to work out some commutator manipulations and found this tool in sympy. It appears to work as expected (but the documentation is virtually non-existent or at least I found little, but see the comment by Dalton Bentley below), but I ran into the following problem. from sympy.physics.quantum import Commutator as Comm from sympy.physics.quantum import Operator A = Operator('A') B = Operator('B') C = Comm(Comm(Comm(A,B),A),B) D = Comm(Comm(Comm(A,B),B),A) E = (C-D).expand(commutator=true) E >>> [[[A,B],A],B] - [[[A,B],B],A] instead of the expected simpler result 0 (since [[[A,B],A],B] = [[

How to replace the the diagonal elements of a matrix by a vector in SymPy?

落花浮王杯 提交于 2019-12-05 20:25:52
I have a vector X which I created like this: from sympy import * x1 = Symbol('x1') x2 = Symbol('x2') x3 = Symbol('x3') X = Matrix([x1, x2, x3]) Then I also have a matrix myMat which just contains ones: myMat = ones(3, 3) Matrix([ [1, 1, 1], [1, 1, 1], [1, 1, 1]]) Now I would like to replace the diagonal of the matrix by my vector X ; my desired outcome looks like this: Matrix([ [x1, 1, 1], [1, x2, 1], [1, 1, x3]]) I can of course do it in a for-loop like this: for ind, el in enumerate(X): myMat[ind, ind] = el but I am wondering whether there is a smarter way of doing that by directly accessing

sympy.solve() doesn't give one of the solutions with LambertW

℡╲_俬逩灬. 提交于 2019-12-05 19:23:11
Background: I am trying to implement a function doing an inverse transform sampling . I use sympy for calculating CDF and getting its inverse function. While for some simple PDFs I get correct results, for a PDF which CDF's inverse function includes Lambert-W function , results are wrong. Example: Consider following example CDF: import sympy as sym y = sym.Symbol('y') cdf = (-y - 1) * sym.exp(-y) + 1 # derived from `pdf = x * sym.exp(-x)` sym.plot(cdf, (y, -1, 5)) Now calculating inverse of this function: x = sym.Symbol('x') inverse = sym.solve(sym.Eq(x, cdf), y) print(inverse) Output: [

Evaluating Jacobian at specific points using sympy

余生颓废 提交于 2019-12-05 19:16:24
I am trying to evaluate the Jacobian at (x,y)=(0,0) but unable to do so. import sympy as sp from sympy import * import numpy as np x,y=sp.symbols('x,y', real=True) J = Function('J')(x,y) f1=-y f2=x - 3*y*(1-x**2) f1x=diff(f1,x) f1y=diff(f1,y) f2x=diff(f2,x) f2y=diff(f2,y) J=np.array([[f1x,f1y],[f2x,f2y]]) J1=J(0,0) print J1 The error corresponding to ---> 16 J1=J(0,0) is TypeError: 'numpy.ndarray' object is not callable The error you're getting is indeed because you're rebinding J to a numpy array which is not a callable. You should use the subs method of sympy expressions to evaluate an

Solving a system of (more than two) linear inequalities

半世苍凉 提交于 2019-12-05 18:49:08
If I use diophantine(2*x+3*y-5*z-77) I receive this result. {(t_0, -9*t_0 - 5*t_1 + 154, -5*t_0 - 3*t_1 + 77)} Fine so far. However, on occasion one might like to constrain x, y and z to be (say) non-negative. When I use an approach like this< reduce_inequalities([0<=t_0, 0<=-9*t_0 - 5*t_1 + 154, 0<=-5*t_0 - 3*t_1 + 77],[t_0, t_1]) I get: NotImplementedError: inequality has more than one symbol of interest Does sympy, sage, prolog, haskell or some other freely available product have means for solving systems of linear inequalities that arise in this way. Thank you! To reason about integers in

Python: Find principal value of an integral numerically

◇◆丶佛笑我妖孽 提交于 2019-12-05 16:55:07
问题 I'm solving the integral numerically using python: where a(x) can take on any value; positive, negative, inside or outside the the [-1;1] and eta is an infinitesimal positive quantity. There is a second outer integral of which changes the value of a(x) I'm trying to solve this using the Sokhotski–Plemelj theorem: However this involves determining the principle value, which I can't find any method to in python. I know it's implemented in Matlab, but does anyone know of either a library or some

Converting hard integral to lambda function with lambdify

不羁的心 提交于 2019-12-05 15:51:25
I would like to lambdify the function Integral(t**t,(t,0,x)) . It works, but my new function, which was returned by lambdify , doesn't return a number but only sympy.integrals.integrals.Integral class. But I don't want that, I want it to return a float number. Here is my code: import sympy as sp import numpy as np f = sp.lambdify(x,sp.integrate(t**t,(t,0,x))) print(f(2)) #return Integral(t**t, (t, 0, 2)) #but i want 2.83387674524687 lambdify doesn't support scipy.integrate.quad directly yet , but it's not difficult to add the appropiate definition. One simply needs to tell lambdify how to

How to find a list of all **args of a function?

只谈情不闲聊 提交于 2019-12-05 13:06:32
How can I find a list of all **args of a function? For example, I know that symbols() take positive=True , real=True , etc. as arguments, and I would like to see a full list of these possible arguments. However, they're not listed in the Sympy Core doc page . And I've dug through the source code itself, but I can't trace and locate what I'm looking for. symbols() function As other answers have noted - one use of **args in the symbols is to pass in Assumptions about the Symbol being created. The list of assumptions you can pass is documented under the Assumptions page as supported predicates .