ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 28 Jan 2011 02:25:15 -0600Different errorshttp://ask.sagemath.org/question/7906/different-errors/Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).
I created a notebook on the uw.sagenb.org server. It contains the text:
http://typewith.me/jmSO3JENxg
Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
Full error here: http://rn0.ru/show/1422/
If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: http://rn0.ru/show/1421/
Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...
Does anyone know the errors?Thu, 27 Jan 2011 21:26:36 -0600http://ask.sagemath.org/question/7906/different-errors/Answer by DSM for <p>Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).</p>
<p>I created a notebook on the <a href="http://uw.sagenb.org">uw.sagenb.org</a> server. It contains the text:
<a href="http://typewith.me/jmSO3JENxg">http://typewith.me/jmSO3JENxg</a></p>
<p>Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>Full error here: <a href="http://rn0.ru/show/1422/">http://rn0.ru/show/1422/</a></p>
<p>If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: <a href="http://rn0.ru/show/1421/">http://rn0.ru/show/1421/</a></p>
<p>Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...</p>
<p>Does anyone know the errors?</p>
http://ask.sagemath.org/question/7906/different-errors/?answer=12022#post-id-12022I couldn't reproduce the dvipng error, but I can explain the "TypeError: 'sage.symbolic.expression.Expression' object is not iterable" problem.
There are several different functions called "plot", including both the Sage one (which knows about and likes Sage expressions), and the plot in the matplotlib package you import in later cells with
<pre><code>from pylab import *</code></pre>
and
<pre><code>from matplotlib.pyplot import figure, axes, plot, xlabel, ylabel, title, \
grid, savefig, show
</code></pre>
This plot function doesn't know about Sage functions and expects an argument that it can loop over, which is exactly what the error message is trying to say: it's expecting something it can iterate over (like a list of points), but the sage expression you pass isn't.
The "sometimes it works, sometimes it doesn't" effect is simply measuring whether or not you executed a reset() in some cell, setting plot back to the Sage one, after you executed the above import, which is why it appears so random-- apparently your cell execution order habits are kind of random. :^)
Keeping the matplotlib functions in their own space by using the "import matplotlib.pyplot as plt"/"plt.plot" approach -- which you do in one cell -- and avoiding either "from pylab import *" or "from matplotlib.pyplot import plot" is a better idea if you're going to want to mix Sage plots and matplotlib plots.
Fri, 28 Jan 2011 00:13:12 -0600http://ask.sagemath.org/question/7906/different-errors/?answer=12022#post-id-12022Answer by manifold for <p>Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).</p>
<p>I created a notebook on the <a href="http://uw.sagenb.org">uw.sagenb.org</a> server. It contains the text:
<a href="http://typewith.me/jmSO3JENxg">http://typewith.me/jmSO3JENxg</a></p>
<p>Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>Full error here: <a href="http://rn0.ru/show/1422/">http://rn0.ru/show/1422/</a></p>
<p>If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: <a href="http://rn0.ru/show/1421/">http://rn0.ru/show/1421/</a></p>
<p>Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...</p>
<p>Does anyone know the errors?</p>
http://ask.sagemath.org/question/7906/different-errors/?answer=12026#post-id-12026YESS... it works.. thousand thanks!!!Fri, 28 Jan 2011 02:14:08 -0600http://ask.sagemath.org/question/7906/different-errors/?answer=12026#post-id-12026Comment by DSM for <p>YESS... it works.. thousand thanks!!!</p>
http://ask.sagemath.org/question/7906/different-errors/?comment=22229#post-id-22229Glad I could help. Since Sage involves a lot of different packages, sometimes it's hard to get them all talking to each other the way you might think they should. But instead of a thousand thanks, I'll settle for you clicking on the checkmark and accepting my answer. :^)Fri, 28 Jan 2011 02:25:15 -0600http://ask.sagemath.org/question/7906/different-errors/?comment=22229#post-id-22229Answer by DSM for <p>Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).</p>
<p>I created a notebook on the <a href="http://uw.sagenb.org">uw.sagenb.org</a> server. It contains the text:
<a href="http://typewith.me/jmSO3JENxg">http://typewith.me/jmSO3JENxg</a></p>
<p>Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>Full error here: <a href="http://rn0.ru/show/1422/">http://rn0.ru/show/1422/</a></p>
<p>If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: <a href="http://rn0.ru/show/1421/">http://rn0.ru/show/1421/</a></p>
<p>Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...</p>
<p>Does anyone know the errors?</p>
http://ask.sagemath.org/question/7906/different-errors/?answer=12025#post-id-12025Yep, x is iterable, as are the other arguments-- but that's not actually what the problem is. In this case the error message is a little deceptive, as it's actually what's inside y which is causing trouble. Let's look at the types involved:
sage: import numpy as np
sage:
sage: x = np.arange(0, 5, 0.1)
sage: y = [e^(-i)+(random()-1/2)/10 for i in x]
sage: ex = [random()/10 for i in y]
sage: ey = [random()/10 for i in y]
sage: for v in x,y,ex,ey:
....: print len(v), type(v), type(v[0])
....:
50 <type 'numpy.ndarray'> <type 'numpy.float64'>
50 <type 'list'> <type 'sage.symbolic.expression.Expression'>
50 <type 'list'> <type 'float'>
50 <type 'list'> <type 'float'>
And you see that the components of y aren't Python floats ('float') or numpy floats ('float64') [the difference between these two doesn't matter here] but Sage symbolic expressions, which (once again) matplotlib doesn't know what to do with.
Here the problem is caused by e:
sage: e
e
sage: type(e)
<type 'sage.symbolic.constants_c.E'>
sage: type(e^(-i))
<type 'sage.symbolic.expression.Expression'>
There are many ways around this problem: simply cast the array to floats, use "np.e", float(e), or (if you don't care about "symbolic" e) simply replace e, etc. The Sage plot functions automatically coerce to numerical values, as they should, but the matplotlib functions (possibly for speed reasons) don't do such a coercion.
Fri, 28 Jan 2011 02:07:16 -0600http://ask.sagemath.org/question/7906/different-errors/?answer=12025#post-id-12025Answer by manifold for <p>Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).</p>
<p>I created a notebook on the <a href="http://uw.sagenb.org">uw.sagenb.org</a> server. It contains the text:
<a href="http://typewith.me/jmSO3JENxg">http://typewith.me/jmSO3JENxg</a></p>
<p>Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>Full error here: <a href="http://rn0.ru/show/1422/">http://rn0.ru/show/1422/</a></p>
<p>If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: <a href="http://rn0.ru/show/1421/">http://rn0.ru/show/1421/</a></p>
<p>Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...</p>
<p>Does anyone know the errors?</p>
http://ask.sagemath.org/question/7906/different-errors/?answer=12024#post-id-12024hi... I just can't get rid of this error:
TypeError: 'sage.symbolic.expression.Expression' object is not iterable
I get it with this code:
http://rn0.ru/show/1428/
(I have restarted the notebook)
And x is defined by.
x = np.arange(0, 5, 0.1)
x is "iterable".. or not?Fri, 28 Jan 2011 01:22:13 -0600http://ask.sagemath.org/question/7906/different-errors/?answer=12024#post-id-12024Answer by manifold for <p>Hi, im new to sage, but i like it. (i Have some expertise with mathematica, but not with sage).</p>
<p>I created a notebook on the <a href="http://uw.sagenb.org">uw.sagenb.org</a> server. It contains the text:
<a href="http://typewith.me/jmSO3JENxg">http://typewith.me/jmSO3JENxg</a></p>
<p>Sometimes a I get the error:
Traceback (click to the left of this block for traceback)
...
TypeError: 'sage.symbolic.expression.Expression' object is not iterable</p>
<p>Full error here: <a href="http://rn0.ru/show/1422/">http://rn0.ru/show/1422/</a></p>
<p>If I want to use latex, in the second lowest field, i get an error:
sh: dvipng: not found
Full error here: <a href="http://rn0.ru/show/1421/">http://rn0.ru/show/1421/</a></p>
<p>Somehow, the fields work sometimes, and sometimes they dont... I have the feeling I would need to "quit the kernel" like in mathematica, from time to time...</p>
<p>Does anyone know the errors?</p>
http://ask.sagemath.org/question/7906/different-errors/?answer=12023#post-id-12023Thanks. That helps!
I think that solve all errors... Fri, 28 Jan 2011 01:04:32 -0600http://ask.sagemath.org/question/7906/different-errors/?answer=12023#post-id-12023