Recall & Review
beginner
How do you access a single element in a NumPy array?
You use square brackets with the index of the element, like
array[index]. For multi-dimensional arrays, use commas to separate indices, like array[row, column].Click to reveal answer
beginner
What is the index of the first element in a NumPy array?
The first element has index 0. NumPy arrays use zero-based indexing, so counting starts at 0.
Click to reveal answer
beginner
How do you access the element in the second row and third column of a 2D NumPy array named
arr?Use
arr[1, 2]. Remember, counting starts at 0, so row 1 is the second row and column 2 is the third column.Click to reveal answer
beginner
What happens if you try to access an index that is out of range in a NumPy array?
NumPy will raise an
IndexError because the index does not exist in the array.Click to reveal answer
beginner
Can you use negative indices to access elements in a NumPy array? What does
array[-1] return?Yes, negative indices count from the end.
array[-1] returns the last element of the array.Click to reveal answer
What does
arr[0] return for a NumPy array arr?✗ Incorrect
NumPy arrays use zero-based indexing, so arr[0] returns the first element.
How do you access the element in the third row and first column of a 2D NumPy array
matrix?✗ Incorrect
Indexing starts at 0, so third row is index 2 and first column is index 0.
What will happen if you try to access
arr[10] when arr has only 5 elements?✗ Incorrect
Accessing an index outside the array size raises an IndexError.
What does
arr[-2] return in a NumPy array?✗ Incorrect
Negative indices count from the end, so -2 is the second last element.
Which of these is the correct way to access a single element in a 3D NumPy array
arr?✗ Incorrect
You can use either comma-separated indices or chained brackets to access elements in multi-dimensional arrays.
Explain how to access a single element in a 2D NumPy array and what indexing rules apply.
Think about how rows and columns are counted starting from zero.
You got /3 concepts.
Describe what happens if you try to access an element outside the bounds of a NumPy array.
What error does Python give when you ask for something that does not exist?
You got /3 concepts.