Unit 8: NumPy functions - Practice Quiz
1 Which NumPy function calculates the square root of each element in an array?
np.sqrt()
np.power()
np.absolute()
np.square()
2
What is the result of np.square(np.array([2, 3]))?
[4, 9]
[4, 6]
[8, 27]
[2, 3]
3 Which NumPy function returns the absolute value of every array element?
np.abs()
np.floor()
np.round()
np.sign()
4
What does np.exp(x) calculate for each element ?
5 Which NumPy function calculates the arithmetic mean of an array?
np.mean()
np.var()
np.std()
np.median()
6
What is the value of np.mean([2, 4, 6])?
12.0
3.0
4.0
6.0
7 Which NumPy function finds the middle value of sorted numerical data?
np.average()
np.percentile()
np.median()
np.maximum()
8 Which NumPy function calculates the standard deviation of array values?
np.sum()
np.std()
np.min()
np.mean()
9 Which function returns a sorted copy of a NumPy array?
np.sort()
np.arrange()
np.order()
np.search()
10
What is the result of np.sort([3, 1, 2])?
[3, 2, 1]
[2, 1, 3]
[1, 2, 3]
[1, 3, 2]
11
What does np.argsort() return?
12
By default, in which order does np.sort() arrange numeric values?
13 Which NumPy function returns indices where a condition is true?
np.sort()
np.where()
np.count()
np.select()
14
For a = np.array([4, 7, 2]), what does np.argmax(a) return?
7
1
0
2
15 Which function returns the index of the smallest array element?
np.min()
np.argmin()
np.minimum()
np.argmax()
16
What is np.searchsorted() mainly used for?
17 Which NumPy function counts the nonzero elements in an array?
np.count_nonzero()
np.size()
np.unique()
np.nonzero()
18
What is the result of np.count_nonzero([0, 5, 0, 3])?
4
2
1
3
19 Which call returns unique values and how many times each value appears?
np.unique(a, return_counts=True)
np.sort(a, return_counts=True)
np.where(a, return_counts=True)
np.size(a, return_counts=True)
20
What does np.count_nonzero(a > 5) count?
5
5
5
5
21
What is the result of np.sqrt(np.abs(np.array([-1, 4, 9])))?
array([1., 16., 81.])
array([1., 4., 9.])
array([-1., 2., 3.])
array([1., 2., 3.])
22
Given a = np.array([[1], [2]]) and b = np.array([10, 20, 30]), what does np.add(a, b) return?
array([11, 22, 32])
array([[11], [22]])
array([[11, 21, 31], [12, 22, 32]])
array([[10, 20, 30], [20, 40, 60]])
23
What is returned by np.floor(np.array([-1.2, 2.8]))?
array([-1., 2.])
array([-1., 3.])
array([-2., 2.])
array([-2., 3.])
24
Given x = np.array([2, 7, 4]) and y = np.array([3, 5, 4]), what is the result of np.maximum(x, y)?
array([2, 7, 4])
array([3, 5, 4])
array([3, 7, 4])
array([2, 5, 4])
25
For a = np.array([[2, 4, 6], [8, 10, 12]]), what does np.mean(a, axis=0) return?
array([2., 4., 6.])
array([4., 10.])
array([6., 8., 10.])
array([5., 7., 9.])
26
What is the value of np.median(np.array([1, 7, 3, 9]))?
4.0
5.0
7.0
3.0
27
Approximately what does np.std(np.array([2, 4, 6])) return when no ddof argument is specified?
1.333
1.633
2.667
2.000
28
What is the result of np.percentile(np.array([0, 10, 20, 30, 40]), 25) using NumPy's standard linear calculation?
20.0
12.5
10.0
15.0
29
Given a = np.array([[3, 1], [4, 2]]), what does np.sort(a, axis=1) return?
array([[1, 2], [3, 4]])
array([[3, 1], [4, 2]])
array([[1, 3], [2, 4]])
array([[3, 1], [2, 4]])
30
What does np.argsort(np.array([30, 10, 20])) return?
array([2, 0, 1])
array([1, 2, 0])
array([0, 2, 1])
array([10, 20, 30])
31
For a = np.array([9, 1, 7, 3]), what value is guaranteed at a[np.argpartition(a, 2)[2]]?
7
9
1
3
32
What is the shape and content of np.sort(np.array([[4, 1], [3, 2]]), axis=None)?
[1, 2, 3, 4]
[[1, 4], [2, 3]]
[4, 3, 2, 1]
[[1, 2], [3, 4]]
33
Given secondary = np.array([2, 1, 1]) and primary = np.array([1, 1, 0]), what does np.lexsort((secondary, primary)) return?
array([2, 1, 0])
array([2, 0, 1])
array([1, 2, 0])
array([0, 1, 2])
34
What does np.where(np.array([2, 7, 4, 9]) > 4) return?
array([1, 3])
[7, 9]
[False, True, False, True]
array([0, 2])
35
For a = np.array([[1, 9, 3], [8, 2, 7]]), what does np.argmax(a, axis=1) return?
array([0, 1])
array([1, 2])
array([1, 0])
array([9, 8])
36
What is returned by np.searchsorted(np.array([10, 20, 30, 40]), 25)?
25
2
1
3
37
What does np.flatnonzero(np.array([[0, 5], [2, 0]])) return?
array([5, 2])
array([1, 2])
array([0, 1])
array([1, 0])
38
For a = np.array([[0, 1, 2], [3, 0, 2]]), what does np.count_nonzero(a, axis=0) return?
array([0, 1, 2])
array([1, 1, 2])
array([1, 2, 1])
array([2, 2])
39
Given a = np.array([2, 1, 2, 3, 1, 2]), which pair is returned by np.unique(a, return_counts=True)?
(array([1, 2, 3]), array([2, 3, 1]))
(array([1, 2, 3]), array([3, 2, 1]))
(array([2, 1, 3]), array([3, 2, 1]))
(array([1, 2, 3]), array([1, 2, 3]))
40
What does np.bincount(np.array([0, 2, 2, 1]), minlength=4) return?
array([1, 1, 2, 4])
array([0, 1, 2, 2])
array([1, 2, 1, 0])
array([1, 1, 2, 0])
41
Given a = np.array([np.nan, -2.0, 3.0]) and b = np.array([2.0, -1.0, np.nan]), what does np.fmax(a, b) return?
array([nan, -2., nan])
array([nan, -1., nan])
array([2., -1., 3.])
array([2., -2., 3.])
42
What are fractional and integral after fractional, integral = np.modf(np.array([-2.75, 3.5]))?
fractional = [0.25, 0.5], integral = [-3., 3.]
fractional = [-0.75, 0.5], integral = [-2., 3.]
fractional = [0.75, 0.5], integral = [-2., 3.]
fractional = [-0.75, 0.5], integral = [-3., 3.]
43
Consider x = np.array([1., 4., 9., 16.]), out = np.full(4, -1.), and np.sqrt(x, out=out, where=np.array([True, False, True, False])). What is out afterward?
array([1., -1., 3., -1.])
array([1., 2., 3., 4.])
array([1., nan, 3., nan])
array([1., 0., 3., 0.])
44
Ignoring normal floating-point rounding, what is np.logaddexp(1000.0, 1000.0) designed to compute without overflowing?
45
Given x = np.array([[1., 2., 9.], [4., 8., 12.]]), what is x - np.mean(x, axis=1, keepdims=True)?
array([[-1.5, -3., 1.5], [1.5, 3., 4.5]])
array([[-4., -3., 4.], [-4., 0., 4.]])
array([[-3., -2., 5.], [-4., 0., 4.]])
array([[-3., -2., 5.], [-8., -4., 0.]])
46
For x = np.array([1., 2., 3.]), what is np.var(x, ddof=1) - np.var(x, ddof=0)?
47
What does np.average(np.array([[1., 3.], [5., 7.]]), axis=1, weights=np.array([1., 3.]), returned=True) return?
(array([2.5, 6.5]), 4.0)
(array([2.5, 6.5]), array([4., 4.]))
(array([2., 6.]), array([4., 4.]))
(array([1.5, 5.5]), array([3., 3.]))
48
Given x = np.array([[np.nan, np.nan], [1.0, np.nan]]), what is np.nanmean(x, axis=1)?
ValueError because one row is all NaN
array([nan, nan]) with an empty-slice warning
array([nan, 1.]) with an empty-slice warning
array([0., 1.]) without any warning
49
Let a = np.array([2, 1, 2, 1]) and b = np.array([1, 2, 0, 1]). What is np.lexsort((a, b))?
array([2, 3, 0, 1])
array([2, 0, 3, 1])
array([3, 1, 2, 0])
array([1, 3, 0, 2])
50
After y = np.partition(np.array([9, 1, 8, 2, 7]), 2), which property is guaranteed?
y[2] is 2; earlier values are no larger and later values are no smaller
y[2] is 7; earlier values are no larger and later values are no smaller
y[2] is 7; earlier values are no smaller and later values are no larger
y is fully sorted, with 7 occupying index 2
51
What is np.argsort(np.array([3, 1, 3, 1]), kind="stable")?
array([3, 1, 0, 2])
array([3, 1, 2, 0])
array([1, 3, 0, 2])
array([1, 3, 2, 0])
52
Given a = np.array([[3, 1], [2, 4], [3, 0]]), what is np.sort(a, axis=0)[::-1]?
array([[3, 4], [2, 1], [3, 0]])
array([[4, 3], [3, 1], [2, 0]])
array([[3, 4], [3, 1], [2, 0]])
array([[3, 1], [3, 4], [2, 0]])
53
For a = np.array([1, 2, 2, 2, 5]), what is np.searchsorted(a, [2, 3], side="right")?
array([4, 4])
array([1, 4])
array([3, 4])
array([4, 5])
54
Let a = np.array([30, 10, 20]) and sorter = np.argsort(a). What does np.searchsorted(a, 25, sorter=sorter) return?
3
0
1
2
55
Given a = np.array([[5, 9], [9, 1]]), what is np.unravel_index(np.argmax(a), a.shape)?
(1, 1)
(0, 1)
(0, 0)
(1, 0)
56
For a = np.array([[0.0, np.nan], [-2.0, 0.0]]), what does np.where(a) return?
(array([0]), array([1]))
(array([0, 1]), array([1, 0]))
(array([1]), array([0]))
(array([0, 1]), array([0, 1]))
57
What is np.count_nonzero(np.array([0.0, np.nan, -0.0, np.inf]))?
1
2
4
3
58
Given a = np.array([[[1, 0], [0, 2]], [[0, 3], [4, 0]]]), what is np.count_nonzero(a, axis=(0, 2), keepdims=True)?
array([[[2], [2]]])
array([[[4]]])
array([[[2, 2]]])
array([[[1], [3]]])
59
What is np.bincount([2, 0, 2, 1], weights=[0.5, 1.5, 2.0, 1.0], minlength=4)?
array([1.0, 1.0, 2.0, 0.0])
array([1.5, 1.0, 2.0, 0.5])
array([1.0, 1.5, 2.0, 0.5])
array([1.5, 1.0, 2.5, 0.0])
60
Given a = np.array([[1, 2], [1, 2], [2, 1], [1, 2]]), what does np.unique(a, axis=0, return_counts=True) return?
(array([[1, 2], [2, 1]]), array([3, 1]))
(array([[1, 2], [2, 1]]), array([2, 2]))
(array([[2, 1], [1, 2]]), array([1, 3]))
(array([1, 2]), array([4, 4]))
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →