Loading

Quipoin Menu

Learn • Practice • Grow

python-for-ai / Indexing and Slicing
mcq
Direction: Choose the correct option

Q1.

Given `a = np.array([1,2,3,4,5])`, what does `a[2]` return?
A. 4
B. 2
C. 1
D. 3
Direction: Choose the correct option

Q2.

What does `a[-1]` do in a NumPy array?
A. Error
B. Returns second last
C. Returns first element
D. Returns last element
Direction: Choose the correct option

Q3.

Given `a = np.array([1,2,3,4,5])`, what is the result of `a[1:4]`?
A. [2,3]
B. [1,2,3]
C. [2,3,4]
D. [1,2,3,4]
Direction: Choose the correct option

Q4.

For a 2D array `a`, what does `a[0,1]` access?
A. First row, first column
B. Second row, second column
C. Row 1, column 0
D. Row 0, column 1
Direction: Choose the correct option

Q5.

What does `a[:, 0]` do for a 2D array?
A. Selects first row
B. Selects first column
C. Selects all rows and first column
D. Both A and C
Direction: Choose the correct option

Q6.

How do you select rows 1 to 2 and columns 2 to 3 in a 2D array `a`?
A. a[1:3][2:4]
B. a[1:2, 2:3]
C. a[:, 1:3]
D. a[1:3, 2:4]
Direction: Choose the correct option

Q7.

What is the result of `a[::2]` for a 1D array?
A. All elements
B. Last two elements
C. First two elements
D. Every second element
Direction: Choose the correct option

Q8.

Boolean indexing: `a[a > 2]` returns
A. Boolean array
B. Error
C. Indices greater than 2
D. Elements greater than 2
Direction: Choose the correct option

Q9.

Given `a = np.arange(12).reshape(3,4)`, what is the shape of `a[1]`?
A. (1,4)
B. (3,4)
C. (3,)
D. (4,)
Direction: Choose the correct option

Q10.

What does `np.where(a > 5)` return?
A. Sorted list
B. Boolean mask
C. Array of values
D. Indices where condition is true