PIXELBANKv8.2.1
Menu

Array Slicing

Problem Statement

Extract portions of a NumPy array using slicing syntax.

Background

NumPy slicing: arr[start:stop:step]

  • start: Starting index (inclusive, default 0)
  • stop: Ending index (exclusive)
  • step: Step size (default 1)

Your Task

Write a function slice_array(arr) that returns a dictionary with:

  • "first_three": First 3 elements as list
  • "last_three": Last 3 elements as list
  • "every_other": Every other element as list
  • "reversed": Reversed array as list

Output Format

Return a dictionary with exactly these four keys.

Example:

Input:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Output:
{'first_three': [0, 1, 2], 'last_three': [7, 8, 9], 'every_other': [0, 2, 4, 6, 8], 'reversed': [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]}
Reasoning:

[:3] for first 3, [-3:] for last 3, [::2] for every other, [::-1] for reverse

Constraints:

  • Array will have at least 3 elements
  • Use slicing syntax arr[start:stop:step]
Editor

Test Results

0/0
Run code to see test results.