benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d5448d1c-9244-5a08-8687-06229ee478b5

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
from scipy.stats import norm


def task_func(n_samples=1000, mu=0, sigma=1, random_seed=0):
    """
    Generates a histogram and a probability density function (PDF) plot for a specified normal distribution.

    This function draws n_samples from a normal distribution defined by mean (mu) and standard deviation (sigma),
    plots a histogram of the samples, and overlays the PDF of the normal distribution. The histogram's density
    is normalized, and the PDF is plotted with a red line with linewidth=2.

    Parameters:
    - n_samples (int): Number of samples for the histogram. Must be greater than 0. Default is 1000.
    - mu (float): Mean for the normal distribution. Default is 0.
    - sigma (float): Standard deviation for the normal distribution. Must be greater than 0. Default is 1.
    - random_seed (int): Random seed for reproducibility. Defaults to 0.

    Returns:
    - ax (matplotlib.axes._axes.Axes): Axes object with the histogram and PDF plotted.
    - samples (numpy.ndarray): Generated sample data.

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

    Example:
    >>> ax, samples = task_func()
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    >>> ax.get_xticklabels()
    [Text(-5.0, 0, '−5'), Text(-4.0, 0, '−4'), Text(-3.0, 0, '−3'), Text(-2.0, 0, '−2'), Text(-1.0, 0, '−1'), Text(0.0, 0, '0'), Text(1.0, 0, '1'), Text(2.0, 0, '2'), Text(3.0, 0, '3'), Text(4.0, 0, '4'), Text(5.0, 0, '5')]
    """

instruct prompt

Generates a histogram and a probability density function (PDF) plot for a specified normal distribution. This function draws n_samples from a normal distribution defined by mean (mu) and standard deviation (sigma), plots a histogram of the samples, and overlays the PDF of the normal distribution. The histogram's density is normalized, and the PDF is plotted with a red line with linewidth=2.
The function should output with:
    ax (matplotlib.axes._axes.Axes): Axes object with the histogram and PDF plotted.
    samples (numpy.ndarray): Generated sample data.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
def task_func(n_samples=1000, mu=0, sigma=1, random_seed=0):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
def task_func(n_samples=1000, mu=0, sigma=1, random_seed=0):

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