[Scipy-tickets] [SciPy] #1544: stats broadcasting in rvs

SciPy Trac scipy-tickets@scipy....
Sun Oct 30 21:26:15 CDT 2011


#1544: stats broadcasting in rvs
-------------------------+--------------------------------------------------
 Reporter:  josefpktd    |       Owner:  somebody   
     Type:  defect       |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  scipy.stats  |     Version:  0.9.0      
 Keywords:               |  
-------------------------+--------------------------------------------------

Comment(by warren.weckesser):

 It gets worse: it seems broadcasting of additional shape parameters does
 not work.  For example, the gamma distribution has one additional
 parameter.  In the following, line [103] works as expected.  I expect line
 [104] to produce an array with shape (2,2), but instead it raises an
 exception.  And I would expect line [105] to complain about incompatible
 shapes.
 {{{
 In [103]: stats.gamma.rvs(2.0, size=(2,2))
 Out[103]:
 array([[ 0.21833399,  0.28700829],
        [ 5.51574125,  1.68236874]])

 In [104]: stats.gamma.rvs(array([2.0, 5.0]), size=(2,2))
 ERROR: An unexpected error occurred while tokenizing input
 The following traceback may be corrupted or invalid
 The error message is: ('EOF in multi-line statement', (102, 0))

 ---------------------------------------------------------------------------
 ValueError                                Traceback (most recent call
 last)
 /Users/warren/training_notes/statistics/<ipython-input-104-856552d2e375>
 in <module>()
 ----> 1 stats.gamma.rvs(array([2.0, 5.0]), size=(2,2))

 /Users/warren/local_scipy/lib/python2.7/site-
 packages/scipy/stats/distributions.pyc in rvs(self, *args, **kwds)
     694             return loc*ones(size, 'd')
     695
 --> 696         vals = self._rvs(*args)
     697         if self._size is not None:
     698             vals = reshape(vals, size)

 /Users/warren/local_scipy/lib/python2.7/site-
 packages/scipy/stats/distributions.pyc in _rvs(self, a)
    3323     """
    3324     def _rvs(self, a):
 -> 3325         return mtrand.standard_gamma(a, self._size)
    3326     def _pdf(self, x, a):
    3327         return exp(self._logpdf(x, a))

 /Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-
 packages/numpy/random/mtrand.so

 in mtrand.RandomState.standard_gamma (numpy/random/mtrand/mtrand.c:8075)()

 /Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/site-
 packages/numpy/random/mtrand.so

 in mtrand.cont1_array (numpy/random/mtrand/mtrand.c:1691)()

 ValueError: shape mismatch: objects cannot be broadcast to a single shape

 In [105]: stats.gamma.rvs(array([2.0, 5.0, 10.0, 15.0]), size=(2,2))
 Out[105]:
 array([[  1.46430036,   4.39812092],
        [ 10.84626667,  16.80892809]])


 }}}

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


More information about the Scipy-tickets mailing list