np.random.laplace
时间: 2023-10-24 15:13:45 浏览: 116
The np.random.laplace function in NumPy generates random numbers from a Laplace distribution.
The Laplace distribution is also known as the double exponential distribution and is a probability distribution that is similar to the normal or Gaussian distribution, but has heavier tails. It is often used in statistics to model data that has large outliers or extreme values.
The function takes several arguments:
- loc: the mean of the distribution (default is 0)
- scale: the scale parameter (default is 1)
- size: the size or shape of the output array (default is None)
Here's an example of how to use np.random.laplace to generate a random sample from a Laplace distribution with mean 0 and scale 1:
``` python
import numpy as np
# Generate 1000 random numbers from a Laplace distribution
sample = np.random.laplace(loc=0, scale=1, size=1000)
# Compute the mean and standard deviation of the sample
mean = np.mean(sample)
std = np.std(sample)
print("Sample mean:", mean)
print("Sample standard deviation:", std)
```
This will output something like:
```
Sample mean: -0.018013482992065523
Sample standard deviation: 1.353447003090671
```
阅读全文