# python: how do I randomly sample a number of samples from a population?

###### Posted By: Anonymous

I have generated 100 samples with specific mean and variance:

```
import numpy as np
mean = 0
variance = 0.1
std_dev = np.sqrt(variance)
t = np.random.normal(mean, std_dev, 100)
print(t)
```

I want to **randomly sample 10 samples** from this population. Is there a way to extract samples randomly?

## Solution

You can use the np.random.choice() function to get a numpy array of 10 random samples (second parameter is the size of the array you want)

```
import numpy as np
mean = 0
variance = 0.1
std_dev = np.sqrt(variance)
t = np.random.normal(mean, std_dev, 100)
print(t)
sample = np.random.choice(t,10)
print(sample)
```

###### Answered By: Anonymous

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.