benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf aed76260-2bed-58d2-ae29-2ace99ac5b42

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
import seaborn as sns


def task_func(array, features=None, seed=None):
    """
    Shuffles the columns of a given 2D numpy array and visualizes it as a heatmap.

    Parameters:
    - array (ndarray): The 2D numpy array to shuffle and plot. It must not be empty.
    - features (list of str, optional): Custom labels for the columns after shuffling.
                                        If not specified, default numerical labels are used.
                                        The list must match the number of columns in 'array'.
    - seed (int, optional): Seed for the random number generator to ensure reproducibility of the shuffle.

    Returns:
    - Axes: The matplotlib Axes object containing the heatmap.

    Raises:
    - ValueError: If 'features' is provided and does not match the number of columns in 'array'; and
                  if 'array' is empty or not 2-dimensional.

    Requirements:
    - numpy
    - matplotlib.pyplot
    - seaborn

    Notes:
    - This function uses the features list as labels for the heatmap's x-axis if features is provided;
      otherwise, it defaults to strings of the numerical labels starting from 1 up to the number of
      columns in the array.

    Example:
    >>> np.random.seed(0)
    >>> array = np.random.rand(2, 5)
    >>> ax = task_func(array, features=['A', 'B', 'C', 'D', 'E'], seed=1)
    >>> type(ax)
    <class 'matplotlib.axes._axes.Axes'>
    >>> ax.collections[0].get_array().data.flatten()
    array([0.60276338, 0.71518937, 0.4236548 , 0.5488135 , 0.54488318,
           0.891773  , 0.43758721, 0.38344152, 0.64589411, 0.96366276])
    """

instruct prompt

Shuffles the columns of a given 2D numpy array and visualizes it as a heatmap.
Note that: Notes: This function uses the features list as labels for the heatmap's x-axis if features is provided; otherwise, it defaults to strings of the numerical labels starting from 1 up to the number of columns in the array.
The function should raise the exception for: ValueError: If 'features' is provided and does not match the number of columns in 'array'; and if 'array' is empty or not 2-dimensional.
The function should output with:
    Axes: The matplotlib Axes object containing the heatmap.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def task_func(array, features=None, seed=None):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def task_func(array, features=None, seed=None):

entry point

task_func

libs

  • numpy
  • matplotlib
  • seaborn

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