benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf abb08ccb-be08-5e27-ba08-f5f1ecf64e09
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import collections
import numpy as np
import matplotlib.pyplot as plt
def task_func(data_dict):
"""
Analyze the uniformity of a distribution represented by a dictionary of categories and their counts,
and create a description to introduce this distribution.
Parameters:
- data_dict (dict): A dictionary with categories as keys and counts as values.
Returns:
- tuple: A tuple containing:
- matplotlib.axes._axes.Axes: The axes object of the histogram.
- str: A message indicating whether the distribution is uniform ("The distribution is uniform.")
or not ("The distribution is not uniform.").
Note:
- If 'data_dict' is empty, the function returns None and a message "The distribution is uniform."
indicating that an empty distribution is considered uniform by default.
- If 'data_dict' is not empty, it calculates the average count of the categories.
- The distribution is considered uniform if the absolute difference between each count and the
average count is less than or equal to 1e-5.
- If any count's absolute difference with the average count is more than 1e-5, the distribution
is considered not uniform.
- The function then creates a histogram of the counts using matplotlib, with the number of bins
being the lesser of 10 or the number of unique counts. The histogram's x-ticks are labeled with
the category names.
Requirements:
- collections
- numpy
- matplotlib
Example:
>>> data = {'A': 2, 'B': 3, 'C': 4, 'D': 1, 'E': 2}
>>> ax, message = task_func(data)
>>> print(message)
The distribution is not uniform.
"""
instruct prompt
Analyze the uniformity of a distribution represented by a dictionary of categories and their counts, and create a description to introduce this distribution.
Note that: If 'data_dict' is empty, the function returns None and a message "The distribution is uniform." indicating that an empty distribution is considered uniform by default. If 'data_dict' is not empty, it calculates the average count of the categories. The distribution is considered uniform if the absolute difference between each count and the average count is less than or equal to 1e-5. If any count's absolute difference with the average count is more than 1e-5, the distribution is considered not uniform. The function then creates a histogram of the counts using matplotlib, with the number of bins being the lesser of 10 or the number of unique counts. The histogram's x-ticks are labeled with the category names.
The function should output with:
tuple: A tuple containing:
matplotlib.axes._axes.Axes: The axes object of the histogram.
str: A message indicating whether the distribution is uniform ("The distribution is uniform.")
or not ("The distribution is not uniform.").
You should write self-contained code starting with:
Code
import collections
import numpy as np
import matplotlib.pyplot as plt
def task_func(data_dict):
code prompt
Code
import collections
import numpy as np
import matplotlib.pyplot as plt
def task_func(data_dict):
entry point
task_func
libs
- collections
- 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