benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 2040273f-6ace-5d73-93e2-c1418268a9ea
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import numpy as np
import matplotlib.pyplot as plt
def task_func(mu, sigma, sample_size):
"""
Generates a numpy array of random samples drawn from a normal distribution
and plots the histogram of these samples. This function specifies the mean (mu),
standard deviation (sigma), and sample size (sample_size), making it useful
for simulating data, conducting statistical experiments, or initializing
algorithms that require normally distributed data with visualization.
Parameters:
mu (float): The mean of the normal distribution.
sigma (float): The standard deviation of the normal distribution.
sample_size (int): The number of samples to draw from the distribution.
Returns:
ndarray: A numpy array of shape (sample_size,) containing samples drawn from the
specified normal distribution.
Notes:
Plots a histogram of the generated samples to show the distribution. The histogram
features:
- X-axis labeled "Sample values", representing the value of the samples.
- Y-axis labeled "Frequency", showing how often each value occurs.
- Title "Histogram of Generated Samples", describing the content of the graph.
- Number of bins set to 30, to discretize the sample data into 30 intervals.
- Alpha value of 0.75 for bin transparency, making the histogram semi-transparent.
- Color 'blue', giving the histogram a blue color.
Requirements:
- numpy
- matplotlib.pyplot
Examples:
>>> data = task_func(0, 1, 1000)
>>> len(data)
1000
>>> isinstance(data, np.ndarray)
True
"""
instruct prompt
Generates a numpy array of random samples drawn from a normal distribution and plots the histogram of these samples. This function specifies the mean (mu), standard deviation (sigma), and sample size (sample_size), making it useful for simulating data, conducting statistical experiments, or initializing algorithms that require normally distributed data with visualization.
Note that: Notes: Plots a histogram of the generated samples to show the distribution. The histogram features: X-axis labeled "Sample values", representing the value of the samples. Y-axis labeled "Frequency", showing how often each value occurs. Title "Histogram of Generated Samples", describing the content of the graph. Number of bins set to 30, to discretize the sample data into 30 intervals. Alpha value of 0.75 for bin transparency, making the histogram semi-transparent. Color 'blue', giving the histogram a blue color.
The function should output with:
ndarray: A numpy array of shape (sample_size,) containing samples drawn from the
specified normal distribution.
You should write self-contained code starting with:
Code
import numpy as np
import matplotlib.pyplot as plt
def task_func(mu, sigma, sample_size):
code prompt
Code
import numpy as np
import matplotlib.pyplot as plt
def task_func(mu, sigma, sample_size):
entry point
task_func
libs
- numpy
- matplotlib
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import