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

SciPy Trac scipy-tickets@scipy....
Sun Oct 30 20:55:22 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):

 Sorry, my previous post missed the key issue, which is the following
 surprising behavior:
 {{{
 In [47]: stats.norm(loc=zeros(5)).rvs()
 Out[47]: array([ 0.0450558,  0.0450558,  0.0450558,  0.0450558,
 0.0450558])

 In [48]: stats.norm.rvs(loc=np.zeros(5))
 Out[48]: array([-0.51003533, -0.51003533, -0.51003533, -0.51003533,
 -0.51003533])

 }}}
 Moreover, the "random" output shown in Out [36] of my previous post looks
 decidedly nonrandom.

 It appears that the given value of the 'size' keyword determines the
 number of random values generated; *after* generating this many samples,
 the result is broadcast with the other arguments.  Smells like a bug to
 me.  Is there a good use case for the current behavior?

 A work-around is to give the size explicitly.  For example:
 {{{
 In [49]: stats.norm.rvs(loc=np.zeros(5), size=5)
 Out[49]: array([-0.18638924,  1.98262646,  1.72811717,  1.3536744 ,
 -0.52807763])

 In [50]: stats.norm.rvs(loc=np.zeros((5,1)), size=5)
 Out[50]:
 array([[-1.40732211,  2.25772776,  0.65555884, -0.85373538, -0.29639723],
        [-1.40732211,  2.25772776,  0.65555884, -0.85373538, -0.29639723],
        [-1.40732211,  2.25772776,  0.65555884, -0.85373538, -0.29639723],
        [-1.40732211,  2.25772776,  0.65555884, -0.85373538, -0.29639723],
        [-1.40732211,  2.25772776,  0.65555884, -0.85373538, -0.29639723]])

 In [51]: stats.norm.rvs(loc=np.zeros((5,1)), size=(5,5))
 Out[51]:
 array([[-0.02202415, -0.38135011,  0.19462152, -0.75862294,  0.26596077],
        [-0.00354676,  0.02734615,  1.39238526, -0.13878292, -1.02193461],
        [ 0.62605714, -1.02270551, -0.33135211, -0.90668301, -1.64451121],
        [ 0.52518014, -0.84042038,  0.70364437, -0.32555321, -0.92514762],
        [-0.07142783,  0.19321172,  1.65455672,  0.67108554,  0.95630008]])

 }}}

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


More information about the Scipy-tickets mailing list