benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf 69343341-9c6f-5d73-8a8b-204161936c7c
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import numpy as np
from sklearn.preprocessing import MinMaxScaler
def task_func(my_dict):
"""
Updates a dictionary by adding a normalized version of a numpy array found under the 'array' key.
The normalization is performed using MinMaxScaler, scaling each value to fall between 0 and 1.
Parameters:
my_dict (dict): A dictionary containing a key 'array' with a numpy array as its value.
Returns:
dict: The dictionary after adding a key 'normalized_array' with the normalized values.
Notes:
The function modifies the dictionary in-place and does not create a new dictionary.
The function assumes that 'array' key exists and its value is a numpy array.
Raises:
TypeError if the value of the 'array' key in my_dict is not a numpy array
Requirements:
- numpy
- sklearn.preprocessing.MinMaxScaler
Examples:
>>> example_dict = {'array': np.array([1, 2, 3, 4, 5])}
>>> result = task_func(example_dict)
>>> 'normalized_array' in result
True
>>> isinstance(result['normalized_array'], np.ndarray)
True
"""
instruct prompt
Updates a dictionary by adding a normalized version of a numpy array found under the 'array' key. The normalization is performed using MinMaxScaler, scaling each value to fall between 0 and 1.
Note that: Notes: The function modifies the dictionary in-place and does not create a new dictionary. The function assumes that 'array' key exists and its value is a numpy array.
The function should raise the exception for: TypeError if the value of the 'array' key in my_dict is not a numpy array
The function should output with:
dict: The dictionary after adding a key 'normalized_array' with the normalized values.
You should write self-contained code starting with:
Code
import numpy as np
from sklearn.preprocessing import MinMaxScaler
def task_func(my_dict):
code prompt
Code
import numpy as np
from sklearn.preprocessing import MinMaxScaler
def task_func(my_dict):
entry point
task_func
libs
- numpy
- sklearn
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