Challenge - 5 Problems
Array Attributes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of array 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)
Attempts:
2 left
💡 Hint
Shape shows rows and columns; size is total elements.
✗ Incorrect
The array has 2 rows and 3 columns, so shape is (2, 3). Total elements are 2*3=6.
❓ Predict Output
intermediate2:00remaining
Determine array data type
What will be printed by this code?
NumPy
import numpy as np arr = np.array([1, 2, 3], dtype='float32') print(arr.dtype)
Attempts:
2 left
💡 Hint
dtype shows the type of elements stored.
✗ Incorrect
The array was created with dtype='float32', so arr.dtype is float32.
❓ data_output
advanced2:00remaining
Number of dimensions of an array
What is the value of
arr.ndim after running this code?NumPy
import numpy as np arr = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]) print(arr.ndim)
Attempts:
2 left
💡 Hint
Count how many levels of nested lists there are.
✗ Incorrect
The array has 3 levels of nested lists, so ndim is 3.
❓ Predict Output
advanced2:00remaining
Shape and size of a reshaped array
What is the output of this code?
NumPy
import numpy as np arr = np.arange(12) arr = arr.reshape(3, 4) print(arr.shape, arr.size)
Attempts:
2 left
💡 Hint
Reshape changes shape but size stays same.
✗ Incorrect
The array is reshaped to 3 rows and 4 columns; size remains 12 elements.
🧠 Conceptual
expert2:00remaining
Understanding dtype impact on size
Given two arrays with the same shape but different dtypes, which statement is true?
Attempts:
2 left
💡 Hint
Size counts elements, not memory used.
✗ Incorrect
Size counts number of elements, not memory. Memory depends on dtype but size attribute is element count.