Recall & Review
beginner
What does the expression
array[2, 3] mean in a 2D NumPy array?It means accessing the element at row 2 and column 3 of the 2D array. Rows and columns start counting from 0.
Click to reveal answer
beginner
How do you select the entire 3rd row from a 2D NumPy array named
arr?Use
arr[2, :]. The colon : means all columns in row 2.Click to reveal answer
beginner
How do you select the entire 2nd column from a 2D NumPy array named
arr?Use
arr[:, 1]. The colon : means all rows in column 1.Click to reveal answer
intermediate
What happens if you use negative indices like
arr[-1, -2] in a 2D NumPy array?Negative indices count from the end.
-1 is the last row, -2 is the second last column.Click to reveal answer
intermediate
How can you select a submatrix from rows 1 to 3 and columns 2 to 4 in a 2D NumPy array
arr?Use slicing:
arr[1:4, 2:5]. The end index is exclusive, so it selects rows 1,2,3 and columns 2,3,4.Click to reveal answer
In a 2D NumPy array, what does
arr[0, 0] access?✗ Incorrect
Indexing starts at 0, so
arr[0, 0] is the element in the first row and first column.How do you select all rows but only the 2nd column from a 2D array
arr?✗ Incorrect
The colon
: means all rows, and 1 selects the second column.What does
arr[-1, :] select in a 2D NumPy array?✗ Incorrect
Negative index
-1 means the last row, and : means all columns.Which slice selects rows 0 to 2 and columns 1 to 3 in
arr?✗ Incorrect
Slicing is exclusive at the end, so
0:3 means rows 0,1,2 and 1:4 means columns 1,2,3.What is the shape of
arr[:, 2] if arr is 5x5?✗ Incorrect
Selecting a single column returns a 1D array with length equal to the number of rows.
Explain how to access a single element, a full row, and a full column in a 2D NumPy array.
Think about how rows and columns are indexed and how slicing works.
You got /3 concepts.
Describe how negative indices work in 2D array indexing and give an example.
Negative numbers start counting backwards from the last element.
You got /3 concepts.