benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 7bcab94f-58a3-5dd8-9a9b-306c70fbe385

Problem

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

complete prompt

from PIL import Image
import numpy as np
from skimage.transform import resize
import matplotlib.pyplot as plt
import os

def task_func(img_path, scale_factors=[0.5, 0.75, 1.5, 2.0]):
    """
    Open an image file and scale it by different scaling factors.
    Display each scaled image using matplotlib and return the scaled images with their Axes.

    Parameters:
    img_path (str): Path to the image file.
    scale_factors (list): List of scaling factors to apply. Default is [0.5, 0.75, 1.5, 2.0].

    Returns:
    list of tuples: Each tuple contains (matplotlib.axes.Axes, numpy.ndarray) representing the Axes and the pixel values of the scaled image.

    Raises:
    FileNotFoundError: If the image file cannot be found.

    Requirements:
    - PIL
    - numpy
    - scikit-image
    - matplotlib.pyplot
    - os

    Example:
    >>> dummy_img_path = "sample.png"
    >>> Image.fromarray(np.random.randint(0, 255, (20, 20, 3), dtype=np.uint8)).save(dummy_img_path)
    >>> result = task_func('sample.png')
    >>> os.remove(dummy_img_path)
    >>> for ax, img in result:
    ...     print(ax.get_title(), img.shape)
    Scale factor: 0.5 (10, 10, 3)
    Scale factor: 0.75 (15, 15, 3)
    Scale factor: 1.5 (30, 30, 3)
    Scale factor: 2.0 (40, 40, 3)
    """

instruct prompt

Open an image file and scale it by different scaling factors. Display each scaled image using matplotlib and return the scaled images with their Axes.
The function should raise the exception for: FileNotFoundError: If the image file cannot be found.
The function should output with:
    list of tuples: Each tuple contains (matplotlib.axes.Axes, numpy.ndarray) representing the Axes and the pixel values of the scaled image.
You should write self-contained code starting with:

Code

from PIL import Image
import numpy as np
from skimage.transform import resize
import matplotlib.pyplot as plt
import os
def task_func(img_path, scale_factors=[0.5, 0.75, 1.5, 2.0]):

code prompt

Code

from PIL import Image
import numpy as np
from skimage.transform import resize
import matplotlib.pyplot as plt
import os
def task_func(img_path, scale_factors=[0.5, 0.75, 1.5, 2.0]):

entry point

task_func

libs

  • matplotlib
  • PIL
  • numpy
  • os
  • skimage

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