Skip to content

stats broadcasting in rvs (Trac #1544) #2069

@scipy-gitbot

Description

@scipy-gitbot

Original ticket http://projects.scipy.org/scipy/ticket/1544 on 2011-10-30 by @josef-pkt, assigned to unknown.

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])

Metadata

Metadata

Assignees

No one assigned

    Labels

    Migrated from TracdefectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.stats

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions