0
0
SciPydata~20 mins

NumPy array foundation review in SciPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NumPy Array Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Understanding NumPy array slicing output
What is the output of this code snippet?
SciPy
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
result = arr[1:, :2]
print(result)
A
[[4 5]
 [7 8]]
B
[[4 5 6]
 [7 8 9]]
C
[[5 6]
 [8 9]]
D
[[2 3]
 [5 6]]
Attempts:
2 left
💡 Hint
Remember that arr[1:, :2] means rows from index 1 to end, columns from index 0 to 1.
data_output
intermediate
2:00remaining
Shape and size of a reshaped NumPy array
Given the code below, what is the shape and size of the array 'reshaped'?
SciPy
import numpy as np
arr = np.arange(12)
reshaped = arr.reshape(3, 4)
print(reshaped.shape, reshaped.size)
A(3, 4) 12
B(12,) 12
C(3, 4) 7
D(4, 3) 12
Attempts:
2 left
💡 Hint
The reshape changes the shape but not the total number of elements.
🔧 Debug
advanced
2:00remaining
Identify the error in NumPy array creation
What error does this code raise?
SciPy
import numpy as np
arr = np.array([1, 2, 3], dtype='float32', shape=(2,2))
AValueError: cannot reshape array of size 3 into shape (2,2)
BTypeError: unexpected keyword argument 'shape'
CSyntaxError: invalid syntax
DNo error, creates a 2x2 array
Attempts:
2 left
💡 Hint
Check the parameters accepted by np.array function.
🧠 Conceptual
advanced
2:00remaining
Broadcasting behavior in NumPy arrays
Which option correctly describes the output shape of the operation below?
SciPy
import numpy as np
a = np.ones((3,1))
b = np.ones((1,4))
c = a + b
print(c.shape)
A(3, 1)
B(1, 1)
C(3, 4)
D(1, 4)
Attempts:
2 left
💡 Hint
Broadcasting expands arrays to compatible shapes for element-wise operations.
🚀 Application
expert
3:00remaining
Find the number of unique rows in a 2D NumPy array
Given the array below, how many unique rows does it contain?
SciPy
import numpy as np
arr = np.array([[1, 2], [3, 4], [1, 2], [5, 6], [3, 4]])
unique_rows = np.unique(arr, axis=0)
print(len(unique_rows))
A2
B4
C5
D3
Attempts:
2 left
💡 Hint
np.unique with axis=0 finds unique rows, not elements.