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

SciPy Trac scipy-tickets@scipy....
Sun Oct 30 20:30:12 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 does broadcast; you just have to give arguments with compatible shapes
 to get the broadcasting that you want:
 {{{
 In [35]: stats.norm(loc=array([0.0, 10.0, 100.0]), scale=10).rvs()
 Out[35]: array([-11.81964492,  -1.81964492,  88.18035508])

 In [36]: stats.norm(loc=array([0.0, 10.0, 100.0]), scale=array([[1.0],
 [10.0]])).rvs()
 Out[36]:
 array([[ -0.59910884,   9.40089116,  99.40089116],
        [ -5.99108836,   4.00891164,  94.00891164]])

 In [37]: stats.norm(loc=array([0.0, 10.0, 100.0]), scale=array([[1.0],
 [10.0]])).rvs(size=(2,3))
 Out[37]:
 array([[  0.52229266,  10.732356  ,  99.6656165 ],
        [  8.80268499,   1.22946138,  92.26971629]])

 In [38]: stats.norm(loc=array([0.0, 10.0, 100.0]), scale=array([[1.0],
 [10.0]])).rvs(size=(3,2,3))
 Out[38]:
 array([[[  -0.30050128,   11.66806108,   98.84132578],
         [ -14.6134854 ,    7.83944809,  117.22379634]],

        [[   1.36336413,    9.35687459,   99.07673582],
         [ -10.38386458,   11.80348136,  114.20432812]],

        [[  -0.45469292,    8.51569085,   99.4730159 ],
         [  -8.69438476,    6.80314046,   86.96980011]]])
 }}}
 In input [36], loc has shape (3,) and scale has shape (2,1), which
 broadast to (2,3).
 In input [38], the desired size is given as (3,2,3).  This shape is
 compatible for broadcasting with loc and scale, so the output has shape
 (3,2,3).

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


More information about the Scipy-tickets mailing list