benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf ada7f6e5-b232-5541-a6ee-49de37e73392

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt

def task_func(mean, std_dev, num_samples):
    """
    Generates a histogram of samples drawn from a normal distribution and overlays
    the probability density function (PDF) of the normal distribution. The plot is titled
    with the fit results, showing the mean and standard deviation used in the generation.
    The function returns both the plot and the samples generated.

    Parameters:
        mean (float): The mean of the normal distribution.
        std_dev (float): The standard deviation of the normal distribution.
        num_samples (int): The number of samples to draw from the distribution.

    Requirements:
    - numpy
    - scipy.stats.norm
    - matplotlib.pyplot

    Notes:
    - The plot title is "Fit results: mean = %.2f, std = %.2f". This title format on the plot displays the mean and standard deviation
        of the normal distribution used to generate the histogram. The values are presented in a format where %.2f
        is replaced by the floating-point numbers corresponding to `mean` and `std_dev` respectively, rounded to two decimal places.
    - The number of bins is set to 30

    Returns:
        tuple: A tuple containing:
            - matplotlib.figure.Figure: The figure object for the plot.
            - numpy.ndarray: An array of samples drawn from the normal distribution.

    Examples:
    >>> import matplotlib
    >>> samples, fig = task_func(0, 1, 1000)
    >>> len(samples)
    1000
    >>> type(samples)
    <class 'numpy.ndarray'>
    >>> isinstance(fig, matplotlib.figure.Figure)
    True

    Note: The actual values in the array depend on the random seed and will vary each time the function is called.
    """

instruct prompt

Generates a histogram of samples drawn from a normal distribution and overlays the probability density function (PDF) of the normal distribution. The plot is titled with the fit results, showing the mean and standard deviation used in the generation. The function returns both the plot and the samples generated.
Note that: Notes: The plot title is "Fit results: mean = %.2f, std = %.2f". This title format on the plot displays the mean and standard deviation of the normal distribution used to generate the histogram. The values are presented in a format where %.2f is replaced by the floating-point numbers corresponding to `mean` and `std_dev` respectively, rounded to two decimal places. The number of bins is set to 30 The actual values in the array depend on the random seed and will vary each time the function is called.
The function should output with:
    tuple: A tuple containing:
    matplotlib.figure.Figure: The figure object for the plot.
    numpy.ndarray: An array of samples drawn from the normal distribution.
You should write self-contained code starting with:

Code

import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
def task_func(mean, std_dev, num_samples):

code prompt

Code

import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
def task_func(mean, std_dev, num_samples):

entry point

task_func

libs

  • numpy
  • matplotlib
  • scipy

Discussion

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

Official source

initial import