0
0
NumPydata~20 mins

Array attributes (shape, dtype, ndim, size) in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Attributes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A(2, 3) 5
B(3, 2) 6
C(2, 3) 6
D(3, 2) 5
Attempts:
2 left
💡 Hint
Shape shows rows and columns; size is total elements.
Predict Output
intermediate
2: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)
Afloat32
Bint32
Cfloat64
Dint64
Attempts:
2 left
💡 Hint
dtype shows the type of elements stored.
data_output
advanced
2: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)
A4
B2
C1
D3
Attempts:
2 left
💡 Hint
Count how many levels of nested lists there are.
Predict Output
advanced
2: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)
A(3, 4) 12
B(4, 3) 12
C(3, 4) 11
D(4, 3) 11
Attempts:
2 left
💡 Hint
Reshape changes shape but size stays same.
🧠 Conceptual
expert
2:00remaining
Understanding dtype impact on size
Given two arrays with the same shape but different dtypes, which statement is true?
ABoth arrays have the same size attribute value.
BThe array with larger dtype uses more memory but size attribute is same.
CThe size attribute changes depending on dtype size in bytes.
DThe array with smaller dtype has a larger size attribute.
Attempts:
2 left
💡 Hint
Size counts elements, not memory used.