What does the shape attribute of a NumPy array tell you?
The shape attribute shows the size of the array in each dimension. For example, (3, 4) means 3 rows and 4 columns.
Click to reveal answer
beginner
What information does the dtype attribute provide in a NumPy array?
The dtype attribute tells you the type of data stored in the array, like integers (int32) or floating-point numbers (float64).
Click to reveal answer
beginner
Explain the ndim attribute of a NumPy array.
The ndim attribute tells you how many dimensions the array has. For example, 1 means a vector, 2 means a matrix, and so on.
Click to reveal answer
beginner
What does the size attribute represent in a NumPy array?
The size attribute shows the total number of elements in the array, no matter how many dimensions it has.
Click to reveal answer
intermediate
How can you use these attributes to understand a NumPy array quickly?
By checking shape, dtype, ndim, and size, you learn the array's layout, data type, number of dimensions, and total elements. This helps you know what kind of data you have and how it is organized.
Click to reveal answer
What does arr.shape return for a NumPy array?
AThe total number of elements in the array
BThe number of dimensions of the array
CThe data type of the array elements
DThe size of each dimension of the array
✗ Incorrect
shape gives the size of each dimension, like (rows, columns).
If arr.ndim is 3, what does it mean?
AThe array has 3 dimensions
BThe array has 3 elements
CThe array has 3 rows
DThe array has 3 columns
✗ Incorrect
ndim tells how many dimensions the array has.
Which attribute tells you the total number of elements in a NumPy array?
Ashape
Bsize
Cdtype
Dndim
✗ Incorrect
size is the total count of all elements in the array.
What does arr.dtype show?
AThe shape of the array
BThe number of dimensions
CThe data type of elements
DThe total size of the array
✗ Incorrect
dtype tells the type of data stored, like int or float.
If an array has shape = (4, 5), what is its size?
A20
B5
C9
D4
✗ Incorrect
Size is the product of shape dimensions: 4 * 5 = 20.
Describe what each of these NumPy array attributes means: shape, dtype, ndim, and size.
Think about how these attributes help you understand the array's structure and data.
You got /5 concepts.
How would you use the shape and size attributes to find out how many elements are in each dimension of a NumPy array?
Remember that size is the total number of elements, and shape tells the size of each dimension.
You got /4 concepts.
Practice
(1/5)
1. Which numpy attribute tells you the total number of elements in an array?
easy
A. size
B. shape
C. ndim
D. dtype
Solution
Step 1: Understand the meaning of each attribute
shape shows dimensions, dtype shows data type, ndim shows number of dimensions, and size shows total elements.
Step 2: Identify the attribute for total elements
The attribute size gives the total number of elements in the array.
Final Answer:
size -> Option A
Quick Check:
Total elements = size [OK]
Hint: Total elements? Use size attribute [OK]
Common Mistakes:
Confusing shape with total elements
Thinking ndim gives total elements
Mixing dtype with size
2. Which of the following is the correct way to get the number of dimensions of a numpy array arr?
easy
A. arr.size()
B. arr.ndim
C. arr.shape()
D. arr.dtype
Solution
Step 1: Recall attribute vs method syntax in numpy
Attributes like ndim and dtype are accessed without parentheses, methods like size() do not exist.
Step 2: Identify correct attribute for number of dimensions
arr.ndim gives the number of dimensions directly.
Final Answer:
arr.ndim -> Option B
Quick Check:
Number of dimensions = arr.ndim [OK]
Hint: Use attribute without () for ndim, size, dtype [OK]