ENH: random.multivariate_normal should broadcast input
See original GitHub issueReproducing code example:
This works well:
m = np.random.normal(size=3)
x = np.random.normal(loc=m, scale=1)
This does not:
P = [[1,0.5],[0.5,1]]
M = np.random.multivariate_normal(mean=[0,0], cov=P, size=3)
X = np.random.multivariate_normal(mean=M, cov=P)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-157-c99a31aba9db> in <module>
1 M = np.random.multivariate_normal(mean=[0,0], cov=P, size=3)
----> 2 X = np.random.multivariate_normal(mean=M, cov=P)
mtrand.pyx in numpy.random.mtrand.RandomState.multivariate_normal()
ValueError: mean must be 1 dimensional
Numpy/Python version information:
1.17.2 / 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
numpy.random.multivariate_normal — NumPy v1.24 Manual
Draw random samples from a multivariate normal distribution. ... New code should use the multivariate_normal method of a Generator instance instead; ...
Read more >jax.random.multivariate_normal - JAX documentation
Sample multivariate normal random values with given mean and covariance. Parameters ... The batch shape ... must be broadcast-compatible with that of mean...
Read more >python - Vectorized implementation for `numpy.random ...
Does multivariate normal theory allow for any sort of scaling? That is generate values with one set of parameters, and scale them to...
Read more >Available CRAN Packages By Name
Available CRAN Packages By Name ; ABCp2, Approximate Bayesian Computational Model for Estimating P2 ; abcrf, Approximate Bayesian Computation via Random Forests.
Read more >Principal component analysis: a review and recent ... - Journals
This article will begin by introducing the basic ideas of PCA, discussing what ... Although for inferential purposes a multivariate normal ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I can phrase this as a feature request - you’d like
multivariate_normal
to work on stacks of matrices. So today, it takesmean
of shape(N,)
and cov of shape(N,N)
, and produces samples of shapesize + (N,)
. The feature request would be to broadcast formean
of shape(..., N)
and cov of shape(..., N, N)
, and produce samples of shape(..., N)
.Does that sound reasonable?
Also, can you replace the traceback with text, so that it’s searchable?
I would like to work on this