benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9ec6a998-fb4e-52f8-8f4e-5fb8beabeaca

Problem

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

complete prompt

import numpy as np
import math

def task_func(data, target, k):
    """
    Calculate the 'k' nearest neighbors by geographic coordinates using a dataset 
    and a target data point. The function returns a list of the 'k' nearest neighbors, 
    sorted in ascending order of their distances from the target.

    Parameters:
    data (DataFrame): The dataset containing geographical coordinates with columns ['Latitude', 'Longitude'].
    target (list): The target data point as [Latitude, Longitude].
    k (int): The number of nearest neighbors to return. Must be a non-negative integer.

    Returns:
    list: List of the 'k' nearest neighbors as [Latitude, Longitude].

    Raises:
    ValueError: If 'k' is a negative integer or not an integer.

    Constants:
    radius of earth is 6371 km

    Requirements:
    - numpy
    - math

    Example:
    >>> data = pd.DataFrame([[14, 25], [1, 22], [7, 8]], columns=['Latitude', 'Longitude'])
    >>> target = [10, 15]
    >>> k = 2
    >>> task_func(data, target, k)
    [[7, 8], [14, 25]]
    """

instruct prompt

Calculate the 'k' nearest neighbors by geographic coordinates using a dataset and a target data point. The function returns a list of the 'k' nearest neighbors, sorted in ascending order of their distances from the target. Constants: radius of earth is 6371 km
The function should raise the exception for: ValueError: If 'k' is a negative integer or not an integer.
The function should output with:
    list: List of the 'k' nearest neighbors as [Latitude, Longitude].
You should write self-contained code starting with:

Code

import numpy as np
import math
def task_func(data, target, k):

code prompt

Code

import numpy as np
import math
def task_func(data, target, k):

entry point

task_func

libs

  • math
  • numpy

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