PIXELBANKv9.1.0
Menu

2D Array Indexing

Problem Statement

Access elements and slices from a 2D NumPy array.

Background

For 2D arrays:

  • arr[i, j] - element at row i, column j
  • arr[i] or arr[i, :] - entire row i
  • arr[:, j] - entire column j

Your Task

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

  • "element_0_0": Element at position (0, 0)
  • "element_1_2": Element at position (1, 2)
  • "row_0": First row as list
  • "col_1": Second column as list

Output Format

Return a dictionary with exactly these four keys.

Example:

Input:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Output:
{'element_0_0': 1, 'element_1_2': 6, 'row_0': [1, 2, 3], 'col_1': [2, 5, 8]}
Reasoning:

Use [row, col] for elements, [row, :] for rows, [:, col] for columns

Constraints:

  • Input will be a 2D array with at least 2 rows and 3 columns
  • Use arr[i, j] syntax for elements
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
2D Array Indexing - Easy | PixelBank