^^^ Never ever use implicit imports (if possible). By writing this explicitly:
from math import sqrt, exp
it becomes clear, what is happening:
>
> x = Symbol('x')
> i = 0
> prior = 1 / sqrt(2*pi) * exp(-1*x**2 / 2)
You are using math.exp() here, so it needs a floating point number,
but sympy doesn't know how to convert "x" to a floating point number,
thus you get the exception below. The solution is to replace the line
from math import sqrt, exp
with
from sympy import sqrt, exp
> p = 1 / (1 + exp(-1*discriminations[i]*(x - difficulties[1])))
> q = 1 - p
> posterior = prior * q
> print posterior
>
> But, when I ran this Python code, I got the following error message:
> Traceback (most recent call last):
> File "/Applications/eclipse/plugins/
> org.python.pydev.debug_1.5.7.2010050621/pysrc/pydevd.py", line 978, in
> <module>
> debugger.run(setup['file'], None, None)
> File "/Applications/eclipse/plugins/
> org.python.pydev.debug_1.5.7.2010050621/pysrc/pydevd.py", line 780, in
> run
> execfile(file, globals, locals) #execute the script
> File "/Users/yjlee/Documents/Worx/EclipseWorx/SymPyProjects/src/
> sympy_test.py", line 44, in <module>
> prior = 1 / sqrt(2*pi) * exp(-1*x**2 / 2)
> File "/Library/Python/2.6/site-packages/sympy/core/basic.py", line
> 2103, in __float__
> raise ValueError("Symbolic value, can't compute")
> ValueError: Symbolic value, can't compute
>
> All I was trying to do was to get a product of two functions, and I
> could not figure out what I did wrong.
>
> Could anyone tell me what I did wrong?
Ondrej
On Oct 16 2010, 1:33 am, Ondrej Certik <ond...@certik.cz> wrote: