benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 37edb181-6b38-516e-9f4d-b87dba6bc4fb

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(arr: np.ndarray) -> (plt.Axes, np.ndarray):
    """
    Plots a histogram of normalized data from an input 2D numpy array alongside the probability density function (PDF)
    of a standard normal distribution.

    Note:
    - Takes in a 2D numpy array as input.
    - Calculates the sum of elements in each row of the array.
    - Normalizes these row sums to have a mean of 0 and a standard deviation of 1.
      - Normalization is achieved by first calculating the mean and standard deviation of the row sums.
      - Each row sum is then transformed by subtracting the mean and dividing by the standard deviation.
      - If the standard deviation is 0 (indicating all row sums are equal), normalization results in an array of zeros with the same shape.
    - Plots a histogram of the normalized data.
      - Uses 30 bins for the histogram.
      - The histogram is density-based, meaning it represents the probability density rather than raw frequencies.
      - The bars of the histogram are semi-transparent (60% opacity) and green in color.
    - Overlays the PDF of a standard normal distribution on the histogram for comparison.
      - The PDF curve is plotted in red with a line width of 2.
      - The range of the PDF curve is set to cover 99% of a standard normal distribution.
    - Sets the title of the plot to "Histogram of Normalized Data with Standard Normal PDF".

    Parameters:
    - arr: A 2D numpy array. The array should contain numerical data.

    Returns:
    - A tuple containing:
      - A matplotlib Axes object with the histogram of the normalized data and the overlaid standard normal PDF.
      - The normalized data as a 1D numpy array.

    Requirements:
    - numpy
    - scipy
    - matplotlib

    Example:
    >>> ax, normalized_data = task_func(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    >>> print(normalized_data)
    [-1.22474487  0.          1.22474487]
    """

instruct prompt

Plots a histogram of normalized data from an input 2D numpy array alongside the probability density function (PDF) of a standard normal distribution.
Note that: Takes in a 2D numpy array as input. Calculates the sum of elements in each row of the array. Normalizes these row sums to have a mean of 0 and a standard deviation of 1. Normalization is achieved by first calculating the mean and standard deviation of the row sums. Each row sum is then transformed by subtracting the mean and dividing by the standard deviation. If the standard deviation is 0 (indicating all row sums are equal), normalization results in an array of zeros with the same shape. Plots a histogram of the normalized data. Uses 30 bins for the histogram. The histogram is density-based, meaning it represents the probability density rather than raw frequencies. The bars of the histogram are semi-transparent (60% opacity) and green in color. Overlays the PDF of a standard normal distribution on the histogram for comparison. The PDF curve is plotted in red with a line width of 2. The range of the PDF curve is set to cover 99% of a standard normal distribution. Sets the title of the plot to "Histogram of Normalized Data with Standard Normal PDF".
The function should output with:
    A tuple containing:
    A matplotlib Axes object with the histogram of the normalized data and the overlaid standard normal PDF.
    The normalized data as a 1D numpy array.
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(arr: np.ndarray) -> (plt.Axes, np.ndarray):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
def task_func(arr: np.ndarray) -> (plt.Axes, np.ndarray):

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