The shape of a NumPy array shows the size of the array in each dimension. It is a tuple where each number tells how many elements are in that dimension.
Click to reveal answer
beginner
How many dimensions does a 1D array have?
A 1D array has exactly one dimension. It looks like a simple list of values.
Click to reveal answer
beginner
What is the shape of this array? np.array([[1, 2, 3], [4, 5, 6]])
The shape is (2, 3) because there are 2 rows and 3 columns.
Click to reveal answer
beginner
What does the ndim attribute of a NumPy array tell you?
The ndim attribute tells you how many dimensions the array has. For example, 1 for 1D, 2 for 2D, and so on.
Click to reveal answer
intermediate
How can you change the shape of an array without changing its data?
You can use the reshape() method to change the shape of an array while keeping the same data.
Click to reveal answer
What is the shape of a 3D array with dimensions 4, 3, and 2?
A(4, 2, 3)
B(3, 2, 4)
C(2, 3, 4)
D(4, 3, 2)
✗ Incorrect
The shape tuple lists dimensions in order: (4, 3, 2).
If an array has shape (5,), what does this mean?
AIt is a 2D array with 5 rows
BIt is a 1D array with 5 elements
CIt is a 3D array with 5 layers
DIt is an empty array
✗ Incorrect
Shape (5,) means one dimension with 5 elements.
Which NumPy attribute gives the number of dimensions of an array?
Ashape
Bsize
Cndim
Ddim
✗ Incorrect
The ndim attribute tells the number of dimensions.
What happens if you try to reshape an array to a shape that does not match the total number of elements?
AIt raises an error
BIt reshapes anyway, filling missing values with zeros
CIt truncates extra elements
DIt duplicates elements to fill the shape
✗ Incorrect
Reshape requires the total number of elements to stay the same, otherwise it raises an error.
What is the shape of np.array([[1, 2], [3, 4], [5, 6]])?
A(3, 2)
B(2, 3)
C(6,)
D(3,)
✗ Incorrect
There are 3 rows and 2 columns, so shape is (3, 2).
Explain what array shape and dimensions mean in simple terms.
Think about rows and columns in a table.
You got /4 concepts.
Describe how you can change the shape of an array and what you must be careful about.
Imagine rearranging blocks without adding or removing any.
You got /4 concepts.
Practice
(1/5)
1. What does the shape of a NumPy array represent?
easy
A. The number of elements along each dimension
B. The total number of elements in the array
C. The data type of the elements
D. The memory size of the array
Solution
Step 1: Understand the meaning of shape
The shape of an array is a tuple that shows how many elements are in each dimension.
Step 2: Differentiate shape from other properties
Shape is not the total count, data type, or memory size, but the size per dimension.
Final Answer:
The number of elements along each dimension -> Option A
Quick Check:
Shape = elements per dimension [OK]
Hint: Shape = count of elements per axis [OK]
Common Mistakes:
Confusing shape with total number of elements
Mixing shape with data type
Thinking shape is memory size
2. Which of the following is the correct way to get the shape of a NumPy array arr?
easy
A. arr.shape
B. arr.shape()
C. shape(arr)
D. arr.get_shape()
Solution
Step 1: Recall NumPy shape syntax
In NumPy, shape is an attribute, not a method, so no parentheses are used.
Step 2: Check each option
arr.shape uses arr.shape correctly; others use incorrect syntax or functions.
The array has 2 rows and 3 columns, so shape is (2, 3).
Step 2: Confirm shape output
Printing arr.shape returns the tuple (2, 3).
Final Answer:
(2, 3) -> Option C
Quick Check:
Rows=2, Columns=3 -> (2, 3) [OK]
Hint: Count rows then columns for shape [OK]
Common Mistakes:
Swapping rows and columns in shape
Thinking shape is total elements
Confusing shape with array size
4. What is wrong with this code snippet?
import numpy as np
arr = np.array([1, 2, 3])
print(arr.shape())
medium
A. print statement syntax is incorrect
B. arr is not a NumPy array
C. The array is empty
D. shape is an attribute, not a method; parentheses cause error
Solution
Step 1: Identify the error source
The code calls arr.shape() with parentheses, but shape is an attribute.
Step 2: Understand attribute vs method
Attributes do not use parentheses; calling with () causes a TypeError.
Final Answer:
shape is an attribute, not a method; parentheses cause error -> Option D
Quick Check:
Attributes no parentheses [OK]
Hint: Remember: shape is attribute, no () [OK]
Common Mistakes:
Using parentheses with shape
Assuming array is empty causes error
Misreading print syntax
5. You have a 3D NumPy array with shape (4, 3, 2). Which of the following operations will correctly reshape it into a 2D array with 4 rows and 6 columns?
hard
A. arr.reshape(12, 2)
B. arr.reshape(4, 6)
C. arr.reshape(6, 4)
D. arr.reshape(2, 12)
Solution
Step 1: Calculate total elements
Original shape (4, 3, 2) means 4*3*2 = 24 elements total.
Step 2: Determine new shape dimensions
New shape (4, 6) means 4*6 = 24 elements, matching total elements.
Step 3: Verify other options
arr.reshape(12, 2), arr.reshape(6, 4), and arr.reshape(2, 12) do not produce 4 rows and 6 columns.
Final Answer:
arr.reshape(4, 6) -> Option B
Quick Check:
4*6=24 matches total elements [OK]
Hint: New shape must keep total elements same [OK]
Common Mistakes:
Mixing up rows and columns in reshape
Choosing shapes with wrong total elements
Forgetting reshape must keep total size
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.