0

Suppose I have a grid of numbers in Python that I have created using

import numpy as np
h = np.linspace(0,20,100)

I am trying to make a random selection within the elements of h in a way that the distribution of the selections follows for example the log-normal distribution, with a given mean and standard deviation. How would I be able to do this?

2 Answers 2

1

May be easier to just draw samples from a lognormal distribution

np.random.lognormal(mean=5,sigma=2,size=10)
Sign up to request clarification or add additional context in comments.

Comments

1

This can be solved very fast. At first you have to find a way to draw random indices following your custom pdf. After you have done this, you can use these indices to draw numbers from 0 to 100 and return the entries of the array at these indices.

To draw the numbers randomly in this way, there are a few ways in ´python´, like this for example. When you have drawn your random indices in this way in an array called indices you can use:

result = h[indices]

to create your desired numpy array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.