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

SciPy Trac scipy-tickets@scipy....
Sat Oct 29 20:18:11 CDT 2011


#1544: stats broadcasting in rvs
-----------------------+----------------------------------------------------
 Reporter:  josefpktd  |       Owner:  somebody   
     Type:  defect     |      Status:  new        
 Priority:  normal     |   Milestone:  Unscheduled
Component:  Other      |     Version:  0.9.0      
 Keywords:             |  
-----------------------+----------------------------------------------------
 I thought that rvs would create a broadcasted random array for different
 loc

 {{{
 import numpy as np
 from scipy import stats


 bins = stats.norm.ppf(np.linspace(0,1,11))

 loc = np.zeros(1000)
 scale = 1

 print bins
 print

 np.random.seed(7654321)
 print np.histogram(stats.norm.rvs(size=loc.shape), bins)[0]
 np.random.seed(7654321)
 print np.histogram(loc + scale * stats.norm.rvs(size=loc.shape), bins)[0]
 np.random.seed(7654321)
 print np.histogram(stats.norm.rvs(loc=loc, scale=scale), bins)[0]
 np.random.seed(7654321)
 print np.histogram(stats.norm(loc=loc, scale=scale).rvs(), bins)[0]
 np.random.seed(7654321)
 }}}

 however it just draws one rvs and broadcasts that, so we get all identical
 rvs

 {{{
 [       -inf -1.28155157 -0.84162123 -0.52440051 -0.2533471   0.
 0.2533471
   0.52440051  0.84162123  1.28155157         inf]

 [ 99 104  92 100 103  95  96  95 108 108]
 [ 99 104  92 100 103  95  96  95 108 108]
 [   0    0 1000    0    0    0    0    0    0    0]
 [   0    0 1000    0    0    0    0    0    0    0]
 >>> rvs = stats.norm(loc=loc, scale=scale).rvs()
 >>> rvs[:10]
 array([-0.70256379, -0.70256379, -0.70256379, -0.70256379, -0.70256379,
        -0.70256379, -0.70256379, -0.70256379, -0.70256379, -0.70256379])
 }}}

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


More information about the Scipy-tickets mailing list