Stack Scans to See Motion

~12 mincode completion

Implement stack_scans(history, offsets) returning the flat 1D observation.

Examples

Three scans, newest first in the observation

Input
stack_scans([[1, 2], [3, 4], [5, 6]], [0, 1, 2])
Output
[5, 6, 3, 4, 1, 2]

Offsets need not be consecutive

Input
stack_scans([[1, 2], [3, 4], [5, 6]], [0, 2])
Output
[5, 6, 1, 2]

At the start of an episode the history is short and clamps

Input
stack_scans([[1, 2]], [0, 1, 2])
Output
[1, 2, 1, 2, 1, 2]

Hints

Hint 1

Reshape so the two arrays broadcast against each other.

Hint 2

Watch for this: stacked oldest first so the current scan was not at the front.

Requirements

  • history: (T, R) scans in time order, most recent last

  • offsets: (K,) steps back from now; 0 is the current scan

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Python
import numpy as np


def stack_scans(history, offsets):
    """
    Concatenate several past lidar scans into one observation.

    Args:
        history: (T, R) scans in time order, most recent last
        offsets: (K,) steps back from now; 0 is the current scan

    Returns:
        (K * R,) array, the scans concatenated in offset order.
        Offsets older than the buffer clamp to the oldest scan.
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.