On 9/9/11 7:05 PM, Renan Birck Pinheiro wrote:
Hi,

I have the following Sage code (it comes from a larger Python program):

from scipy.stats import norm, randint

signalD = randint(0,2);
signal = signalD.rvs(10);

It successfully generates the array "signal" with 10 random elements.

However, this fails:

list_plot(signal)
         Traceback (click to the left of this block for traceback)
         ...
         ValueError: The truth value of an array with more than one
element is ambiguous. Use a.any() or a.all()

Any ideas? Using a syntax like list_plot([i for i in signal]) does work,
however.



It's a bug in how list_plot checks for an empty list. We can see in the error message (below):

sage: import numpy as np
sage: x=np.array(range(10))
sage: x
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
sage: list_plot(x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/Users/grout/<ipython console> in <module>()

/Users/grout/sage/local/lib/python2.6/site-packages/sage/plot/plot.pyc in list_plot(data, plotjoined, **kwargs)
   3561     """
   3562     from sage.plot.all import line, point
-> 3563     if data == {} or data == () or data == []:
   3564         return Graphics()


list_plot is trying to check to see if there is an empty list/tuple/dict. I think it should just do len(data). The real root of the error we are seeing is that numpy arrays compare element-by-element (IIRC) for the dictionary comparison:

sage: x=={}
array([False, False, False, False, False, False, False, False, False, False], dtype=bool)

Then trying to do bool(resulting array) throws the error.

Anyways, your workaround works great for now. I've opened http://trac.sagemath.org/sage_trac/ticket/11787 to track this issue.

Thanks,

Jason

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to