benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d8712f0c-afc4-5a64-8188-1d22819aefe3

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


def task_func(P, T):
    """
    Calculate the product of a matrix "P" and a 3D tensor "T" with numpy and then visualize the
    result in 3D with matplotlib. The product of the matrix and tensor is based on the Einstein summation.
    
    Note:
    This function only accepts numpy matrices/arrays.

    Parameters:
    P (numpy.ndarray): The input matrix with shape (N, 3), where N is the number of rows.
    T (numpy.ndarray): The input tensor with shape (3, 3, 3).

    Returns:
    tuple:
        - result (numpy.ndarray): The product of matrix P and tensor T with shape (N, 3).
        - ax (mpl_toolkits.mplot3d.axes3d.Axes3D): The 3D visualization of the result.

    Requirements:
    - numpy
    - matplotlib.pyplot

    Example:
    >>> P = np.array([[6, 2, 7], [1, 1, 8], [8, 7, 1]])
    >>> T = np.random.rand(3, 3, 3)
    >>> result, ax = task_func(P, T)
    >>> type(result)
    <class 'numpy.ndarray'>
    >>> type(ax)
    <class 'mpl_toolkits.mplot3d.axes3d.Axes3D'>
    """

instruct prompt

Calculate the product of a matrix "P" and a 3D tensor "T" with numpy and then visualize the result in 3D with matplotlib. The product of the matrix and tensor is based on the Einstein summation.
Note that: This function only accepts numpy matrices/arrays.
The function should output with:
    tuple:
    result (numpy.ndarray): The product of matrix P and tensor T with shape (N, 3).
    ax (mpl_toolkits.mplot3d.axes3d.Axes3D): The 3D visualization of the result.
You should write self-contained code starting with:

Code

import numpy as np
import matplotlib.pyplot as plt
def task_func(P, T):

code prompt

Code

import numpy as np
import matplotlib.pyplot as plt
def task_func(P, T):

entry point

task_func

libs

  • numpy
  • matplotlib

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