Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which function reshapes an array without changing its data?
Not quite. Try another option.
Answer: reshape()
The reshape() function returns a new view of the array with a different shape but the same data.
Question 13 of 60 · array operations · Easy
What does np.arange(0, 5) produce?
Not quite. Try another option.
Answer: [0, 1, 2, 3, 4]
np.arange(0, 5) generates values from 0 up to, but not including, 5.
Question 14 of 60 · statistical functions · Easy
Which NumPy function computes the average of array elements?
Not quite. Try another option.
Answer: np.mean()
np.mean() returns the arithmetic mean (average) of the array elements.
Question 15 of 60 · statistical functions · Easy
What does np.max() return for a NumPy array?
Not quite. Try another option.
Answer: The largest element
np.max() returns the maximum (largest) value among the array elements.
Question 16 of 60 · statistical functions · Easy
Which function computes the standard deviation of a NumPy array?
Not quite. Try another option.
Answer: np.std()
np.std() calculates the standard deviation, a measure of how spread out the values are.
Question 17 of 60 · statistical functions · Easy
Given a = np.array([2, 4, 6]), what does np.sum(a) return?
Not quite. Try another option.
Answer: 12
np.sum() adds all elements together: .
Question 18 of 60 · broadcasting · Easy
What does broadcasting in NumPy allow you to do?
Not quite. Try another option.
Answer: Operate on arrays of different shapes
Broadcasting lets NumPy perform arithmetic on arrays of different but compatible shapes without explicit copying.
Question 19 of 60 · broadcasting · Easy
When you add a scalar to a NumPy array, broadcasting causes the scalar to be:
Not quite. Try another option.
Answer: Applied to every element
Through broadcasting, the scalar is virtually stretched to match the array shape and added to each element.
Question 20 of 60 · broadcasting · Easy
For broadcasting to work between two arrays, their dimensions must be:
Not quite. Try another option.
Answer: Compatible or equal to 1
Broadcasting requires dimensions to be equal or one of them to be 1, so the smaller array can be stretched.
Question 21 of 60 · arrays vs lists · Medium
Given import numpy as np, what is the output of the following code?
python
lst = [1, 2, 3]
arr = np.array([1, 2, 3])
print(lst 2, arr 2)
Not quite. Try another option.
Answer: [1, 2, 3, 1, 2, 3] [2 4 6]
For a Python list, * 2 repeats the elements, producing [1, 2, 3, 1, 2, 3]. For a NumPy array, * 2 performs element-wise multiplication, producing [2 4 6].
Question 22 of 60 · arrays vs lists · Medium
Which statement best explains why NumPy arrays are generally faster than Python lists for numerical computation?
Not quite. Try another option.
Answer: Arrays store homogeneous data in contiguous memory and use vectorized C operations
NumPy arrays hold elements of one type packed in contiguous memory, allowing fast vectorized operations implemented in C, unlike lists that store references to scattered Python objects.
Question 23 of 60 · data types · Medium
What will be the dtype of the array created below?
python
arr = np.array([1, 2, 3.0, 4])
Not quite. Try another option.
Answer: float64
NumPy upcasts to a common type. Since one element is a float, all elements are promoted to float64.
Question 24 of 60 · data types · Medium
What is the output of the following code?
python
arr = np.array([1, 2, 3], dtype=np.int8)
arr[0] = 300
print(arr[0])
Not quite. Try another option.
Answer: 44
int8 holds values from to . Assigning wraps around: , so the stored value is .
Question 25 of 60 · data types · Medium
Which code correctly converts a float array a into an integer array without changing the original?
Not quite. Try another option.
Answer: b = a.astype(np.int32)
astype() returns a new array with the specified dtype, leaving the original unchanged. dtype is an attribute, not a conversion method.
Question 26 of 60 · array operations · Medium
Given arr = np.arange(12).reshape(3, 4), what does arr[:, 1] return?
Not quite. Try another option.
Answer: [1 5 9]
arr[:, 1] selects column index 1 from every row. The reshaped array rows are [0 1 2 3], [4 5 6 7], [8 9 10 11], so column 1 is [1 5 9].
Question 27 of 60 · array operations · Medium
What is the result of the following code?
python
a = np.array([[1, 2], [3, 4]])
print(a.sum(axis=0))
Not quite. Try another option.
Answer: [4 6]
axis=0 sums down the columns: .
Question 28 of 60 · array operations · Medium
Given arr = np.array([10, 20, 30, 40, 50]), what does arr[::-2] return?
Not quite. Try another option.
Answer: [50 30 10]
A step of -2 starts at the last element and moves backward by two: 50, then 30, then 10.
Question 29 of 60 · array operations · Medium
What is the difference between np.dot(a, b) and a * b for two 2D arrays of the same shape?
Not quite. Try another option.
Answer: np.dot performs matrix multiplication while * performs element-wise multiplication
np.dot (or @) computes the matrix product using row-by-column sums, whereas * multiplies corresponding elements position by position.
Question 30 of 60 · array operations · Medium
What is the output of the following code?
python
arr = np.array([1, 2, 3, 4, 5])
print(arr[arr % 2 == 0])
Not quite. Try another option.
Answer: [2 4]
Boolean indexing keeps only elements where the condition is True. The even elements are 2 and 4.
Question 31 of 60 · statistical functions · Medium
Given arr = np.array([2, 4, 6, 8]), what does np.std(arr) compute and its approximate value?
Not quite. Try another option.
Answer: Population standard deviation,
By default np.std uses (population). Mean is ; variance is , and .
Question 32 of 60 · statistical functions · Medium
For a = np.array([[1, 2], [3, 4]]), what does np.mean(a, axis=1) return?
Not quite. Try another option.
Answer: [1.5 3.5]
axis=1 computes the mean across each row: .
Question 33 of 60 · statistical functions · Medium
Which function returns the index of the maximum value in an array rather than the value itself?
Not quite. Try another option.
Answer: np.argmax
np.argmax returns the index position of the largest element, while np.max/np.amax return the value and np.maximum compares two arrays element-wise.
Question 34 of 60 · statistical functions · Medium
What is the output of the following code?
python
arr = np.array([3, 1, 4, 1, 5, 9, 2])
print(np.median(arr))
Not quite. Try another option.
Answer: 3.0
Sorted, the array is [1 1 2 3 4 5 9]. With 7 elements, the middle (4th) value is 3.
Question 35 of 60 · statistical functions · Medium
Given arr = np.array([10, 20, 30, 40]), what does np.cumsum(arr) return?
Not quite. Try another option.
Answer: [10 30 60 100]
cumsum returns the running total: 10, 10+20=30, 30+30=60, 60+40=100.
Question 36 of 60 · broadcasting · Medium
What is the result of the following code?
python
a = np.array([[1], [2], [3]])
b = np.array([10, 20, 30])
print((a + b).shape)
Not quite. Try another option.
Answer: (3, 3)
Shapes (3, 1) and (3,) broadcast to (3, 3): the column vector stretches across columns and the row vector across rows.
Question 37 of 60 · broadcasting · Medium
Which pair of array shapes CANNOT be broadcast together?
Not quite. Try another option.
Answer: (4, 3) and (2,)
Broadcasting requires trailing dimensions to be equal or one of them to be 1. Comparing 3 with 2 fails, so (4, 3) and (2,) are incompatible.
Question 38 of 60 · broadcasting · Medium
What is the output of the following code?
python
a = np.array([1, 2, 3])
print(a + 5)
Not quite. Try another option.
Answer: [6 7 8]
The scalar 5 is broadcast to match the array shape and added element-wise, producing [6 7 8].
Question 39 of 60 · broadcasting · Medium
Given a of shape (2, 3) and b of shape (3,), what is the shape of a * b?
Not quite. Try another option.
Answer: (2, 3)
b of shape (3,) broadcasts across the two rows of a, so the result keeps shape (2, 3).
Question 40 of 60 · array operations · Medium
What is the output of the following code?
python
arr = np.array([1, 2, 3])
arr2 = arr
arr2[0] = 99
print(arr[0])
Not quite. Try another option.
Answer: 99
Assignment arr2 = arr creates a reference, not a copy, so both names point to the same array. Modifying arr2 also changes arr. Use arr.copy() to avoid this.
For a Python list, * repeats the sequence, producing [1, 2, 3, 1, 2, 3]. For a NumPy array, * performs element-wise multiplication, producing [2 4 6].
Question 42 of 60 · arrays vs lists · Hard
A NumPy array stores integers while an equivalent Python list stores the same values. Why does the NumPy array typically consume far less memory?
Not quite. Try another option.
Answer: It stores raw values in a contiguous, fixed-type buffer without per-element object overhead
A Python list holds pointers to individual int objects, each carrying object overhead. A NumPy array stores raw fixed-size values in one contiguous block, eliminating that per-element overhead.
int8 holds values from to . Assigning overflows and wraps around: .
Question 44 of 60 · data types · Hard
Given arr = np.array([1, 2, 3]), which operation returns a new array of type float64 without modifying arr?
Not quite. Try another option.
Answer: arr.astype(np.float64)
astype creates a copy converted to the given dtype. view reinterprets the same bytes (giving wrong values), setting .dtype reinterprets in place, and reshape does not change dtype.
Question 45 of 60 · data types · Hard
What is the resulting dtype of np.array([True, 2, 3.5])?
Not quite. Try another option.
Answer: float64
NumPy upcasts all elements to a common type. Combining bool, int, and float promotes everything to float64.
Question 46 of 60 · array operations · Hard
What does the following print?
Python
import numpy as np
a = np.arange(6).reshape(2, 3)
b = a.T
b[0, 0] = 99
print(a[0, 0])
Not quite. Try another option.
Answer: 99
.T returns a view sharing the same data buffer, not a copy. Modifying b[0, 0] (which maps to a[0, 0]) changes a as well.
Question 47 of 60 · array operations · Hard
Given a = np.array([10, 20, 30, 40]), what does a[::-1][1:3] return?
Not quite. Try another option.
Answer: array([30, 20])
a[::-1] reverses to [40, 30, 20, 10]. Slicing [1:3] takes indices 1 and 2, giving [30, 20].
Question 48 of 60 · array operations · Hard
Consider:
Python
import numpy as np
a = np.array([1, 2, 3, 4, 5])
mask = a % 2 == 0
a[mask] = 0
print(a)
What is the output?
Not quite. Try another option.
Answer: [1 0 3 0 5]
The boolean mask selects even elements (2 and 4). Assigning 0 to those positions leaves odd values unchanged, giving [1 0 3 0 5].
Question 49 of 60 · array operations · Hard
What is the result of np.arange(12).reshape(3, 4)[:, 1::2]?
Not quite. Try another option.
Answer: [[1 3], [5 7], [9 11]]
All rows are kept; columns 1::2 selects indices 1 and 3. For each row this yields the values at those columns: 1,3 / 5,7 / 9,11.
Question 50 of 60 · array operations · Hard
Which statement about np.reshape(a, (-1, 3)) is correct when a has 12 elements?
Not quite. Try another option.
Answer: The -1 is inferred as , producing a array
A -1 dimension is automatically computed so the total size matches. With 12 elements and 3 columns, the inferred dimension is .
Question 51 of 60 · statistical functions · Hard
For a = np.array([[1, 2], [3, 4]]), what does a.mean(axis=0) return?
Not quite. Try another option.
Answer: array([2., 3.])
axis=0 averages down the columns (collapsing rows): column 0 gives , column 1 gives .
Question 52 of 60 · statistical functions · Hard
What does np.std(np.array([2, 4, 4, 4, 5, 5, 7, 9])) return (population standard deviation)?
Not quite. Try another option.
Answer: 2.0
The mean is . Squared deviations sum to ; variance ; standard deviation . NumPy defaults to the population formula ().
Question 53 of 60 · statistical functions · Hard
Given an array containing a np.nan, which function ignores the NaN when computing the mean?
Not quite. Try another option.
Answer: np.nanmean
np.mean and np.average propagate NaN, returning nan. Only the nan-prefixed functions like np.nanmean skip NaN values.
Question 54 of 60 · statistical functions · Hard
What is the difference between a.var() and a.var(ddof=1) for a sample array?
Not quite. Try another option.
Answer: ddof=1 divides by (sample variance) instead of (population variance)
The divisor is . Default ddof=0 uses (population); ddof=1 uses , giving the unbiased sample variance.
Question 55 of 60 · statistical functions · Hard
For a = np.array([[1, 5], [3, 2]]), what does np.argmax(a) return?
Not quite. Try another option.
Answer: 1
By default argmax operates on the flattened array [1, 5, 3, 2]. The maximum value 5 is at flattened index 1.
Question 56 of 60 · broadcasting · Hard
Given a of shape (3, 1) and b of shape (1, 4), what is the shape of a + b?
Not quite. Try another option.
Answer: (3, 4)
Broadcasting stretches each size-1 dimension to match the other operand. (3, 1) and (1, 4) combine to (3, 4).
Question 57 of 60 · broadcasting · Hard
Which pair of shapes CANNOT be broadcast together?
Not quite. Try another option.
Answer: (3, 4) and (2, 4)
Broadcasting requires each aligned dimension to be equal or one of them to be 1. The leading dimensions 3 and 2 are neither equal nor 1, so they are incompatible.
Question 58 of 60 · broadcasting · Hard
What does the following produce?
Python
import numpy as np
a = np.array([[1], [2], [3]])
b = np.array([10, 20, 30])
print((a + b).shape)
Not quite. Try another option.
Answer: (3, 3)
a has shape (3, 1) and b is treated as (1, 3). Broadcasting stretches both to (3, 3).
Question 59 of 60 · broadcasting · Hard
To subtract the per-column mean from each element of a (100, 5) array X, which expression works via broadcasting?
Not quite. Try another option.
Answer: X - X.mean(axis=0)
X.mean(axis=0) has shape (5,), matching the column axis. It broadcasts across all 100 rows, subtracting each column's mean. axis=1 would compute row means instead.
Question 60 of 60 · broadcasting · Hard
What is the result of the following?
Python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([[0], [1], [2]])
print(a * b)
Not quite. Try another option.
Answer: [[0 0 0], [1 2 3], [2 4 6]]
a is (3,) → (1, 3) and b is (3, 1). Broadcasting to (3, 3) multiplies each row of a by the row's scalar from b: 0, 1, and 2 respectively.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of ECE181 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of ECE181 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.