question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: random.multivariate_normal should broadcast input

See original GitHub issue

Reproducing 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:open
  • Created 4 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
eric-wiesercommented, Oct 31, 2019

I think I can phrase this as a feature request - you’d like multivariate_normal to work on stacks of matrices. So today, it takes mean of shape (N,) and cov of shape (N,N), and produces samples of shape size + (N,). The feature request would be to broadcast for mean 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?

1reaction
CloseChoicecommented, May 10, 2020

I would like to work on this

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found