📘
Basic Array Indexing
EasyNumPy Indexing
Problem Statement
Access elements from a NumPy array using basic indexing.
Background
NumPy supports powerful indexing:
- arr[i] - single element
- arr[i, j] - element at row i, column j (for 2D)
- Negative indices count from end
Your Task
Write a function get_elements(arr) that returns a dictionary with:
- "first": First element
- "last": Last element
- "middle": Middle element (use len//2 for index)
Output Format
Return a dictionary with exactly these three keys.
Example:
Input:
[10, 20, 30, 40, 50]
Output:
{'first': 10, 'last': 50, 'middle': 30}Reasoning:
Index 0 for first, -1 for last, len//2 for middle
Constraints:
- Use standard indexing arr[i]
- Use negative indexing for last element
- Array will have at least 1 element
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.