0
0
NumPydata~20 mins

ndarray as the core data structure in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ndarray Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of ndarray shape and size
What is the output of the following code snippet?
NumPy
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape, arr.size)
A(3, 2) 6
B(2, 3) 6
C(2, 3) 5
D(3, 2) 5
Attempts:
2 left
💡 Hint
Shape gives rows and columns, size is total elements.
data_output
intermediate
2:00remaining
Result of ndarray slicing
What is the output of slicing the array below?
NumPy
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
print(arr[1:4])
A[20 30 40 50]
B[10 20 30]
C[30 40 50]
D[20 30 40]
Attempts:
2 left
💡 Hint
Slicing excludes the last index.
🔧 Debug
advanced
2:00remaining
Identify the error in ndarray reshaping
What error does this code raise?
NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
arr.reshape(2, 3)
AValueError: cannot reshape array of size 5 into shape (2,3)
BTypeError: reshape argument must be tuple
CIndexError: index out of range
DNo error, reshaping works
Attempts:
2 left
💡 Hint
Total elements must match new shape.
visualization
advanced
2:00remaining
Visualize the effect of ndarray transpose
What is the output of transposing this array?
NumPy
import numpy as np
arr = np.array([[1, 2], [3, 4], [5, 6]])
print(arr.T)
A
[[1 3 5]
 [2 4 6]]
B
[[1 2 3]
 [4 5 6]]
C
[[1 2]
 [3 4]
 [5 6]]
D
[[6 5 4]
 [3 2 1]]
Attempts:
2 left
💡 Hint
Transpose flips rows and columns.
🧠 Conceptual
expert
2:00remaining
Understanding ndarray broadcasting rules
Given arrays a with shape (3,1) and b with shape (1,4), what is the shape of a + b?
A(3, 1)
B(1, 1)
C(3, 4)
D(1, 4)
Attempts:
2 left
💡 Hint
Broadcasting matches dimensions by expanding singleton dimensions.