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), as a plain Python int
- "element_1_2": Element at position (1, 2), as a plain Python int
- "row_0": First row as a Python list
- "col_1": Second column as a Python list
Output Format
Return a dictionary with exactly these four keys.
Example
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
{'element_0_0': 1, 'element_1_2': 6, 'row_0': [1, 2, 3], 'col_1': [2, 5, 8]}arris a grid of integers. Positions count from zero, so position means row , column , and the top-left number sits at .element_0_0: row 0, column 0 holds .element_1_2: row 1 is , and its column 2 (the third entry, not the second) is .row_0: fix and let run over every column: gives[1, 2, 3].col_1: fix and let run over every row: gives[2, 5, 8], the middle number of each row read top to bottom.- The two elements are single plain integers; the row and column are ordinary lists. Notice a row's length equals the number of columns and a column's length equals the number of rows: for a input,
row_0has 4 entries butcol_1has only 2.
Constraints
- Input will be a 2D array with at least 2 rows and 3 columns
- Use arr[i, j] syntax for elements