benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf b47c3167-4090-5dfa-a0dc-53191d45af4b

Problem

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

complete prompt

from functools import reduce
from itertools import combinations
import numpy as np


def task_func(shape=(3, 3), low=1, high=10, seed=None):
    """
    Generate a matrix of specified shape and random numbers within a specified 
    range. Generate a list of all possible number pairs (all possible combinations of
    two numbers which are in the matrix) in the matrix.
    Calculate the sum of the products of all pairs.

    Parameters:
    shape (tuple): Shape of the matrix, default is (3, 3).
    low (int): Lower bound of the random number generation, inclusive (default is 1).
    high (int): Upper bound of the random number generation, exclusive (default is 10).
    seed (int, optional): Seed for the random number generator for reproducible results. If None, the random number 
                          generator is initialized without a seed (default is None).

    Returns:
    int: The sum of products of all possible number pairs within the generated matrix.
    np.array: The generated matrix.

    Raises:
    ValueError: If high <= low

    Requirements:
    - functools.reduce
    - itertools.combinations
    - numpy

    Example:
    >>> task_func((2, 2), 1, 5, seed=42)
    (43, array([[3, 4],
           [1, 3]]))

    >>> task_func((5, 4), seed=1)
    (4401, array([[6, 9, 6, 1],
           [1, 2, 8, 7],
           [3, 5, 6, 3],
           [5, 3, 5, 8],
           [8, 2, 8, 1]]))
    """

instruct prompt

Generate a matrix of specified shape and random numbers within a specified range. Generate a list of all possible number pairs (all possible combinations of two numbers which are in the matrix) in the matrix. Calculate the sum of the products of all pairs. >>> task_func((5, 4), seed=1) (4401, array([[6, 9, 6, 1], [1, 2, 8, 7], [3, 5, 6, 3], [5, 3, 5, 8], [8, 2, 8, 1]]))
The function should raise the exception for: ValueError: If high <= low
The function should output with:
    int: The sum of products of all possible number pairs within the generated matrix.
    np.array: The generated matrix.
You should write self-contained code starting with:

Code

from functools import reduce
from itertools import combinations
import numpy as np
def task_func(shape=(3, 3), low=1, high=10, seed=None):

code prompt

Code

from functools import reduce
from itertools import combinations
import numpy as np
def task_func(shape=(3, 3), low=1, high=10, seed=None):

entry point

task_func

libs

  • itertools
  • numpy
  • functools

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