Unit 8: NumPy functions - Practice Quiz

ECAP776 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which NumPy function calculates the square root of each element in an array?

Mathematical functions Easy
A. np.sqrt()
B. np.power()
C. np.absolute()
D. np.square()

2 What is the result of np.square(np.array([2, 3]))?

Mathematical functions Easy
A. [4, 9]
B. [4, 6]
C. [8, 27]
D. [2, 3]

3 Which NumPy function returns the absolute value of every array element?

Mathematical functions Easy
A. np.abs()
B. np.floor()
C. np.round()
D. np.sign()

4 What does np.exp(x) calculate for each element ?

Mathematical functions Easy
A. The value
B. The value
C. The value
D. The value

5 Which NumPy function calculates the arithmetic mean of an array?

Statistical functions Easy
A. np.mean()
B. np.var()
C. np.std()
D. np.median()

6 What is the value of np.mean([2, 4, 6])?

Statistical functions Easy
A. 12.0
B. 3.0
C. 4.0
D. 6.0

7 Which NumPy function finds the middle value of sorted numerical data?

Statistical functions Easy
A. np.average()
B. np.percentile()
C. np.median()
D. np.maximum()

8 Which NumPy function calculates the standard deviation of array values?

Statistical functions Easy
A. np.sum()
B. np.std()
C. np.min()
D. np.mean()

9 Which function returns a sorted copy of a NumPy array?

Sort functions Easy
A. np.sort()
B. np.arrange()
C. np.order()
D. np.search()

10 What is the result of np.sort([3, 1, 2])?

Sort functions Easy
A. [3, 2, 1]
B. [2, 1, 3]
C. [1, 2, 3]
D. [1, 3, 2]

11 What does np.argsort() return?

Sort functions Easy
A. Ranks of unique values
B. Values that sort the array
C. Indices that sort the array
D. Counts of sorted values

12 By default, in which order does np.sort() arrange numeric values?

Sort functions Easy
A. Ascending order
B. Random order
C. Original order
D. Descending order

13 Which NumPy function returns indices where a condition is true?

Search functions Easy
A. np.sort()
B. np.where()
C. np.count()
D. np.select()

14 For a = np.array([4, 7, 2]), what does np.argmax(a) return?

Search functions Easy
A. 7
B. 1
C. 0
D. 2

15 Which function returns the index of the smallest array element?

Search functions Easy
A. np.min()
B. np.argmin()
C. np.minimum()
D. np.argmax()

16 What is np.searchsorted() mainly used for?

Search functions Easy
A. Finding the array mean
B. Reversing array elements
C. Removing duplicate values
D. Finding an insertion index

17 Which NumPy function counts the nonzero elements in an array?

Counting functions Easy
A. np.count_nonzero()
B. np.size()
C. np.unique()
D. np.nonzero()

18 What is the result of np.count_nonzero([0, 5, 0, 3])?

Counting functions Easy
A. 4
B. 2
C. 1
D. 3

19 Which call returns unique values and how many times each value appears?

Counting functions Easy
A. np.unique(a, return_counts=True)
B. np.sort(a, return_counts=True)
C. np.where(a, return_counts=True)
D. np.size(a, return_counts=True)

20 What does np.count_nonzero(a > 5) count?

Counting functions Easy
A. Elements different from 5
B. Elements less than 5
C. Elements greater than 5
D. Elements equal to 5

21 What is the result of np.sqrt(np.abs(np.array([-1, 4, 9])))?

Mathematical functions Medium
A. array([1., 16., 81.])
B. array([1., 4., 9.])
C. array([-1., 2., 3.])
D. 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?

Mathematical functions Medium
A. array([11, 22, 32])
B. array([[11], [22]])
C. array([[11, 21, 31], [12, 22, 32]])
D. array([[10, 20, 30], [20, 40, 60]])

23 What is returned by np.floor(np.array([-1.2, 2.8]))?

Mathematical functions Medium
A. array([-1., 2.])
B. array([-1., 3.])
C. array([-2., 2.])
D. 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)?

Mathematical functions Medium
A. array([2, 7, 4])
B. array([3, 5, 4])
C. array([3, 7, 4])
D. array([2, 5, 4])

25 For a = np.array([[2, 4, 6], [8, 10, 12]]), what does np.mean(a, axis=0) return?

Statistical functions Medium
A. array([2., 4., 6.])
B. array([4., 10.])
C. array([6., 8., 10.])
D. array([5., 7., 9.])

26 What is the value of np.median(np.array([1, 7, 3, 9]))?

Statistical functions Medium
A. 4.0
B. 5.0
C. 7.0
D. 3.0

27 Approximately what does np.std(np.array([2, 4, 6])) return when no ddof argument is specified?

Statistical functions Medium
A. 1.333
B. 1.633
C. 2.667
D. 2.000

28 What is the result of np.percentile(np.array([0, 10, 20, 30, 40]), 25) using NumPy's standard linear calculation?

Statistical functions Medium
A. 20.0
B. 12.5
C. 10.0
D. 15.0

29 Given a = np.array([[3, 1], [4, 2]]), what does np.sort(a, axis=1) return?

Sort functions Medium
A. array([[1, 2], [3, 4]])
B. array([[3, 1], [4, 2]])
C. array([[1, 3], [2, 4]])
D. array([[3, 1], [2, 4]])

30 What does np.argsort(np.array([30, 10, 20])) return?

Sort functions Medium
A. array([2, 0, 1])
B. array([1, 2, 0])
C. array([0, 2, 1])
D. array([10, 20, 30])

31 For a = np.array([9, 1, 7, 3]), what value is guaranteed at a[np.argpartition(a, 2)[2]]?

Sort functions Medium
A. 7
B. 9
C. 1
D. 3

32 What is the shape and content of np.sort(np.array([[4, 1], [3, 2]]), axis=None)?

Sort functions Medium
A. A one-dimensional array [1, 2, 3, 4]
B. A two-dimensional array [[1, 4], [2, 3]]
C. A one-dimensional array [4, 3, 2, 1]
D. A two-dimensional array [[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?

Sort functions Medium
A. array([2, 1, 0])
B. array([2, 0, 1])
C. array([1, 2, 0])
D. array([0, 1, 2])

34 What does np.where(np.array([2, 7, 4, 9]) > 4) return?

Search functions Medium
A. A tuple containing array([1, 3])
B. A value array containing [7, 9]
C. A Boolean array [False, True, False, True]
D. A tuple containing array([0, 2])

35 For a = np.array([[1, 9, 3], [8, 2, 7]]), what does np.argmax(a, axis=1) return?

Search functions Medium
A. array([0, 1])
B. array([1, 2])
C. array([1, 0])
D. array([9, 8])

36 What is returned by np.searchsorted(np.array([10, 20, 30, 40]), 25)?

Search functions Medium
A. 25
B. 2
C. 1
D. 3

37 What does np.flatnonzero(np.array([[0, 5], [2, 0]])) return?

Search functions Medium
A. array([5, 2])
B. array([1, 2])
C. array([0, 1])
D. array([1, 0])

38 For a = np.array([[0, 1, 2], [3, 0, 2]]), what does np.count_nonzero(a, axis=0) return?

Counting functions Medium
A. array([0, 1, 2])
B. array([1, 1, 2])
C. array([1, 2, 1])
D. 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)?

Counting functions Medium
A. (array([1, 2, 3]), array([2, 3, 1]))
B. (array([1, 2, 3]), array([3, 2, 1]))
C. (array([2, 1, 3]), array([3, 2, 1]))
D. (array([1, 2, 3]), array([1, 2, 3]))

40 What does np.bincount(np.array([0, 2, 2, 1]), minlength=4) return?

Counting functions Medium
A. array([1, 1, 2, 4])
B. array([0, 1, 2, 2])
C. array([1, 2, 1, 0])
D. 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?

Mathematical functions Hard
A. array([nan, -2., nan])
B. array([nan, -1., nan])
C. array([2., -1., 3.])
D. array([2., -2., 3.])

42 What are fractional and integral after fractional, integral = np.modf(np.array([-2.75, 3.5]))?

Mathematical functions Hard
A. fractional = [0.25, 0.5], integral = [-3., 3.]
B. fractional = [-0.75, 0.5], integral = [-2., 3.]
C. fractional = [0.75, 0.5], integral = [-2., 3.]
D. 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?

Mathematical functions Hard
A. array([1., -1., 3., -1.])
B. array([1., 2., 3., 4.])
C. array([1., nan, 3., nan])
D. array([1., 0., 3., 0.])

44 Ignoring normal floating-point rounding, what is np.logaddexp(1000.0, 1000.0) designed to compute without overflowing?

Mathematical functions Hard
A. Approximately
B. Approximately
C. Exactly
D. Positive infinity

45 Given x = np.array([[1., 2., 9.], [4., 8., 12.]]), what is x - np.mean(x, axis=1, keepdims=True)?

Statistical functions Hard
A. array([[-1.5, -3., 1.5], [1.5, 3., 4.5]])
B. array([[-4., -3., 4.], [-4., 0., 4.]])
C. array([[-3., -2., 5.], [-4., 0., 4.]])
D. 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)?

Statistical functions Hard
A.
B.
C.
D.

47 What does np.average(np.array([[1., 3.], [5., 7.]]), axis=1, weights=np.array([1., 3.]), returned=True) return?

Statistical functions Hard
A. (array([2.5, 6.5]), 4.0)
B. (array([2.5, 6.5]), array([4., 4.]))
C. (array([2., 6.]), array([4., 4.]))
D. (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)?

Statistical functions Hard
A. A ValueError because one row is all NaN
B. array([nan, nan]) with an empty-slice warning
C. array([nan, 1.]) with an empty-slice warning
D. 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))?

Sort functions Hard
A. array([2, 3, 0, 1])
B. array([2, 0, 3, 1])
C. array([3, 1, 2, 0])
D. array([1, 3, 0, 2])

50 After y = np.partition(np.array([9, 1, 8, 2, 7]), 2), which property is guaranteed?

Sort functions Hard
A. y[2] is 2; earlier values are no larger and later values are no smaller
B. y[2] is 7; earlier values are no larger and later values are no smaller
C. y[2] is 7; earlier values are no smaller and later values are no larger
D. y is fully sorted, with 7 occupying index 2

51 What is np.argsort(np.array([3, 1, 3, 1]), kind="stable")?

Sort functions Hard
A. array([3, 1, 0, 2])
B. array([3, 1, 2, 0])
C. array([1, 3, 0, 2])
D. array([1, 3, 2, 0])

52 Given a = np.array([[3, 1], [2, 4], [3, 0]]), what is np.sort(a, axis=0)[::-1]?

Sort functions Hard
A. array([[3, 4], [2, 1], [3, 0]])
B. array([[4, 3], [3, 1], [2, 0]])
C. array([[3, 4], [3, 1], [2, 0]])
D. 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")?

Search functions Hard
A. array([4, 4])
B. array([1, 4])
C. array([3, 4])
D. 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?

Search functions Hard
A. 3
B. 0
C. 1
D. 2

55 Given a = np.array([[5, 9], [9, 1]]), what is np.unravel_index(np.argmax(a), a.shape)?

Search functions Hard
A. (1, 1)
B. (0, 1)
C. (0, 0)
D. (1, 0)

56 For a = np.array([[0.0, np.nan], [-2.0, 0.0]]), what does np.where(a) return?

Search functions Hard
A. (array([0]), array([1]))
B. (array([0, 1]), array([1, 0]))
C. (array([1]), array([0]))
D. (array([0, 1]), array([0, 1]))

57 What is np.count_nonzero(np.array([0.0, np.nan, -0.0, np.inf]))?

Counting functions Hard
A. 1
B. 2
C. 4
D. 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)?

Counting functions Hard
A. array([[[2], [2]]])
B. array([[[4]]])
C. array([[[2, 2]]])
D. array([[[1], [3]]])

59 What is np.bincount([2, 0, 2, 1], weights=[0.5, 1.5, 2.0, 1.0], minlength=4)?

Counting functions Hard
A. array([1.0, 1.0, 2.0, 0.0])
B. array([1.5, 1.0, 2.0, 0.5])
C. array([1.0, 1.5, 2.0, 0.5])
D. 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?

Counting functions Hard
A. (array([[1, 2], [2, 1]]), array([3, 1]))
B. (array([[1, 2], [2, 1]]), array([2, 2]))
C. (array([[2, 1], [1, 2]]), array([1, 3]))
D. (array([1, 2]), array([4, 4]))