[Scipy-tickets] [SciPy] #1537: scipy circmean exception when using non-flattened array

SciPy Trac scipy-tickets@scipy....
Tue Oct 11 18:56:47 CDT 2011


#1537: scipy circmean exception when using non-flattened array
---------------------------------+------------------------------------------
 Reporter:  pfctdayelise         |       Owner:  somebody   
     Type:  defect               |      Status:  new        
 Priority:  normal               |   Milestone:  Unscheduled
Component:  scipy.stats          |     Version:  0.9.0      
 Keywords:  circmean, morestats  |  
---------------------------------+------------------------------------------
 >>> import numpy
 >>> import scipy.stats.morestats
 >>> def getmean(a):
 ...     radiansA = numpy.deg2rad(a)
 ...     radiansMean = scipy.stats.morestats.circmean(radiansA)
 ...     degreesMean = numpy.rad2deg(radiansMean)
 ...     return degreesMean
 ...
 >>> getmean([90,100,80,85])
 88.741025855464059
 >>> getmean(numpy.array([90,100,80,85]))
 88.741025855464059
 >>> getmean(numpy.array([[90],[100],[80],[85]]))
 array([ 88.74102586])
 >>> getmean(numpy.array([[90,100],[80,85]]))
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "<stdin>", line 3, in getmean
   File "/work/gfe-devel-1.1.6/lib/python2.7/site-
 packages/scipy/stats/morestats.py", line 1306, in circmean
     if (res < 0):
 ValueError: The truth value of an array with more than one element is
 ambiguous. Use a.any() or a.all()
 >>> getmean(numpy.array([[90,100],[80,85]]).flat)
 88.741025855464059


 Suggestion:
 https://github.com/scipy/scipy/blob/master/scipy/stats/morestats.py#L1345
 - should not specify axis=0. The grid needs to be flattened, but according
 to http://www.scipy.org/Numpy_Example_List_With_Doc#head-
 a5c6c840c3816a9e5d322d9b11e854c10fdc9cbe "The default is to compute the
 mean of the flattened array" which is what we want.

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1537>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list